IS337 Doc Spring 2010 CH2

Embed Size (px)

Citation preview

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    1/35

    College of Computer and Information SciencesInformation systems Department

    IS337 - Database Lab

    Instructor: Najmuddin Malik

    Academic Year: 2010-2011Total Pages 188

    Page | 1

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    2/35

    Course reference book:OCA Oracle Database 11g Administration IISBN 978-0-07-159104-1Published by Oracle Press

    Title Page No

    Ch 2: Exploring Database Architecture 5Ch 4: Creating an Oracle Database 37Ch 5: Managing Oracle Instance 37Ch 6: Configuring the Oracle Net Environment 47Ch 7: Managing Database Storage Structure 72 Ch 8: Administering User Security 102Ch 15: Backup and recovery Concepts 118 Ch 16: Performing Database Backups 118Ch 17: Performing Database Recovery 175

    Page | 2

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    3/35

    Metadata ViewsAn Oracle 10g database contains two types of meta data views.

    1. Data dictionary views: Oracle 10g contains over 1,300 dictionary views. Their namesbegin with dba_, all_, and user_.

    2. Dynamic performance views: Oracle 10g contains over 350 dynamic performanceviews. Most of these views have names that begin with v$.

    >select TABLE_NAME, BLOCKS, EMPTY_BLOCKS from user_tables;

    >select owner, TABLE_NAME, BLOCKS, EMPTY_BLOCKS from all_tables;

    >select owner,TABLE_NAME,BLOCKS,EMPTY_BLOCKS from dba_tables;

    >select FILE_ID, FILE_NAME, STATUS, BYTES, BLOCKS from dba_data_files;

    >select FILE#, NAME, STATUS, BYTES, BLOCKS from v$datafile;

    Comparison of Data dictionary and dynamic performance views

    Dictionary Views Dynamic Performance Views

    Views usually have plural names. Views generally have singular names.

    Available only when database is OPEN. Some are available when database isNOT OPEN.

    Data is generally UPPERCASE. The data is generally lowercase.

    Data is static, not change when db is shutdown. Data lost when database shutdown.

    Page | 3

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    4/35

    Some Useful Viewsdba_clu_columnsdba_clustersdba_constraintsdba_data_filesdba_db_links

    dba_extentsdba_free_spacedba_ind_columnsdba_ind_partitionsdba_ind_subpartitionsdba_locksdba_objectsdba_outstanding_alertsdba_part_key_columnsdba_part_tablesdba_password_limits

    dba_profilesdba_resourse_limitsdba_role_privsdba_rolesdba_rollback_segsdba_segmentsdba_subpart_columnsdba_sys_privsdba_tab_partitionsdba_tab_privsdba_tab_subpartitionsdba_tablesdba_tablespacesdba_temp_filesdba_ts_quotasdba_usersv$archivev$archive_destv$archived_logv$backup_datafilev$backup_devicev$backup_piecev$backup_redologv$backup_setv$controlfilev$controlfile_record_sectionv$databasev$datafilev$datafile_headerv$db_object_cache

    v$dbfilev$dblinkv$instancev$librarycachev$log

    v$log_historyv$logfilev$parameterv$rollnamev$rollstatv$sessionv$session_waitv$sgav$sgastatv$sort_segmentv$sql

    v$sqlareav$sqltextv$sysstatv$system_parameterv$tempfilev$transactionv$recovery_file_destv$flash_recovery_area_usage

    rc_archived_logrc_backup_controlfilerc_backup_piecerc_backup_redologrc_backup_setrc_controlfile_copyrc_databaserc_database_block_corruptionrc_datafilerc_datafile_copyrc_rman_configurationrc_rman_statusrc_stored_scriptrc_stored_script_linerc_tablespacerc_unusable_backupfile_detail

    role_role_privsrole_tab_privsrole_sys_privs

    Page | 4

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    5/35

    CH 2: Exploring the Oracle Database Architecture

    Topic Page No

    1. Oracle Architecture 6 2. Memory Structures 7 3. Background Threads of an Instance 8

    4. Least Recently Used (LRU) algorithm 17 5. Calculating size of SGA and its Components 18 6. Oracle Physical structures 21

    Initialization file 22

    Control file 24Data files 24Redo Log files 26

    Alert Log files 27 Trace files 28 Password files 31

    7. User Session 32 8. Checkpoint 339. Connection Request Failure reasons 34

    10.SQL Statement Execution Steps 35 11. Instance recovery at instance startup (SMON) 35

    Page | 5

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    6/35

    Oracle Architecture

    As a DBA, you take care of each of each tasks, as well as others.1. Selecting server hardware on which database software will run.2. Install and configuring the Oracle 10g software on the server.3. Creating database itself.4. Creating and managing the tables and other objects.5. Creating and managing database users.6. Establish reliable backups and recovery process for the database.7. Monitoring and Tuning database performance

    To work as a DBA, you need to completely understand Oracles underlying architecture andits mechanism. Understand the relationship between Oracles memory structures,background process, and I/O activities on physical structure. Oracle server architecture canbe broken into two main categories

    Following are Oracle structures and together we call them Oracle Database Server. Oracle Instance

    Memory structuresProcessesPhysical structures / Oracle database (group of 3 type of physical structures)

    Oracle Server instance is a collection of server side processed and memory areas thatOracle used for managing access to database. Oracle Server instance main memorystructure called System Global Area (SGA), and Oracle background processes. The SGA, ata minimum, is made up of four components: The Shared Pool, The Database Buffer Cache,

    The java Pool, and Redo Log Buffer. Other components of the SGA, like Large Pool may alsoexist on the Oracle system depending on which optional features you chose to use.The Oracle background processes are System Monitor (SMON), Process Monitor (PMON),Database Writer (DBW0), Log Writer (LGWR), and Checkpoint (CKPT). Several other Oracleprocesses may also be running on the system, depending on which optional features youhave decided to implement.

    The SGA and the required background processes acquire space in the servers memoryimmediately upon startup of the Oracle server. Four initialization parameters are the primarydeterminant of the SGA memory requirements.

    The Oracle database is made up of a set of physical files that reside on the host server diskdrives. These files are called control files, data files, and redo logs. Additional physical filesthat are associated with the Oracle database, but are not technically part of the database, arepassword file, the PFILE/SPFILE and archived redo log files.

    Page | 6

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    7/35

    Memory Structures

    1. System Global Area (SGA)2. Program Global Areas (PGA)

    System Global Area (SGA)Database BufferCache store data needed for SQL statements issued in user processes. Itimproves performance for subsequent statements on same data. SGA allows users to makedata changes quickly in memory.

    Shared Pool Caches the most recently used SQL statements that have been issued by

    database users. Library Cache (mandatory): Used for storing parsed SQL statement text andstatement execution plan for reuse.

    Dictionary cache / Row cache (mandatory): Used for storing recently accessedinformation (table, column definition, user name, PWD and privileges)

    Redo Log Buffertemporarily stores in memory the redo log information generated by DML inuser sessions until Oracle writes information to disk. Redo log is small amount of informationproduced and saved to redo changes made to database by insert, update, alter, dropstatements.

    Large Pool buffers Caches data forlarge I/O operations such as RMAN backup and restoreactivities and shared server components.

    Java Pool Caches the most recently used Java objects and application code when OracleJVM option is used.

    Streams Pool Caches the data associated with queued message requests whenOracle Advance Queuing(OAQ) option is used.

    Program Global Areas (PGA)PGA is created for each user and it stores user-specific session information.

    1. Bind variables2. Session variables. (uid, ip address of client machine, time connect, program, status, ..)

    Page | 7

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    8/35

    Background Threads of an Instance.

    At the user level two processes allow a user to interact with instance and, ultimately with the

    database. They are User process and Server process. The user process exists either on theusers own pc or on the middle-tier application server. Once the connection is made, the userestablishes a session in the instance. After establishing a session, each user then starts aServer process on the host server. It is the server process that is responsible for performingthe tasks that actually allow the user to interact with the database.In a Dedicated Server configuration each end user has his/her own Server Process. WhenShared Server option is used, several end-users share one or more Server Processes.Server process management is an important aspect of overall database performance.

    Oracle Background ProcessesFive Oracle background processes are required and several background processes are

    optional.

    Required Oracle Background Processes.

    Data base Writer (DBWn): Writes modified data block from data buffer cache back to datafiles on disk. At least one DBWn may have more DBW0, DBW1, DBW3 .DBW9DBWR writes dirty data blocks from buffer cache to disk.

    1. Writes when need room in buffer cache.2. When DBWr is told to write data to disk by LGWR at checkpoint.

    Log Writer (LGWR): Write Redo Log entries from redo log buffer to online redo log files ondisk.

    Checkpoint (CKPT): Periodically database performs checkpoints. During checkpoints DBWnwrites all modified data blocks in memory back to data files. CKPT updates the data filesheader following a checkpoint event.

    System Monitor (SMON): performs internal operation.1. Periodically coalesces the free space. It works during times of low activity.2. Instance recovery handled after database starts up if necessary.3. De-allocates space in temporary segments no longer in use.

    Process Monitor (PMON) Cleans up messes left by dedicated server with no user sessionattached to it. Roll back changes and kills the dedicated server memory and CPU usage.

    Page | 8

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    9/35

    Optional Oracle Background Processes

    Archive (ARCn) automatically back ups transactions log files. After LGWR fills them with redolog entries.

    Recoverer (RECO): Distributed database is a collection of individual database that appear toan application and user as a single database. A distributed transaction is a transaction thatupdates data in multiple databases. To protect integrity of data through out a distributeddatabase, Oracle used mechanism. The transaction might be completed at some servers,while left in doubt at other. RECO is used in such instances. RECO automatically wakes upto resolve all in-doubt distributed transactions as they happen.

    Dispatcher (Dnnn): Assigns users request to request queue in Oracle Shared Servermode.

    Shared Server (Snnn): Server processes that are shared among several users when OracleShared Serverfeature is used.

    Job Queue Monitor (CJQn): Assigns jobs to Job Queue processes when using oracle jobschedulingfeature.

    Job Queue (Jnnn): Executes database jobs that have been schedules using Oracle Jobschedulingfeature.

    Queue Monitor (QMNn): Monitors the messages in the message queue when OracleAdvanced Queuingfeature is used.

    Parallel Query Slave (Qnnn): Used to carry out portions of a large overall query when OracleParallel Queryfeature is used.

    Memory Manager (MMAN): Manages the size of each individual SGA component whenOracleAutomatic Shared Memory Managementfeature is used.

    Memory Monitor (MMON): Gathers and analyzes statistic used by theAutomatic WorkloadRepositoryfeatured.

    Memory Monitor Light (MMNL): Gathers and analyzes statistic used by theAutomaticWorkload Repositoryfeatured.

    Recovery Writer (RVWR): Writes recovery information to disk when Oracle FlashbackDatabase Recoveryfeature is used.

    Change Tracking Writer (CTWR): keeps track of which database blocks have changed whenOracle Incremental Recovery Managerfeature is used.

    Page | 9

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    10/35

    User and Server Processes relationship

    Page | 10

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    11/35

    The basic Oracle Architecture Components

    Page | 11

    Initialization file (spfile)Control filesData filesLog files

    Alert fileTrace files

    Password file

    Oracle Instance

    Physical

    Structures

    Memory Structures

    SGA PGA

    DBWn ARCn DnnnLGWR RECO SnnnPMON CJQn MMANSMON Jnnn MMONCKPT QMNn MMNL

    Qnnn RVWR

    CTWR

    Processes

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    12/35

    Some Important Memory Areas and Processes

    Page | 12

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    13/35

    Page | 13

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    14/35

    Subdivision of SGA Areas

    Page | 14

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    15/35

    Some of Oracle memory areas and processes description

    Page | 15

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    16/35

    Oracle SGA, background processes and some physical structures

    Page | 16

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    17/35

    Least Recently Used (LRU) algorithm

    Oracle used a Least Recently Used (LRU) algorithm to manage the contents of the SharedPooland Database Buffer Cache. Oracle keeps frequently accessed SQL statements anddatabase buffers in memory longer, improving the overall performance of the server byminimizing parsing and physical I/O.

    The size of the SGA can be managed by manually or automatically. In automatic mode, theinstance itself will monitor the utilization of each SGA component and adjust their sizeaccordingly, relative to a predefined maximum allowable aggregate SGA size. OracleallocatesSGA memory into chunks called granules. These granules of memory aredynamically allocated or de-allocated from the buffer cache, shared pool, large pool, and

    java poolas needed according to the demand placed on these areas by application users.SGAgranules can be 4mb, 8mb, or 16mb in size, depending on the server OS and size ofSGA.

    Whether the instance operates in manual or automatic mode is determined by settings in aconfiguration file called parameter initialization file. There are two type of parameterinitialization files Parameter File (PFiles), and Server Parameter Files (SPFiles). You can useeither type of file to configure instance and database operations. You can specify more than250 documented configuration parameters in Pfile/Spfile. Oracle recommends that youset only about 30 basic initialization parameters manually.

    Cache STATUS

    Cache Hit/Cache Get:Cache hit happens when an application request data that is already in memory cache.

    Cache Miss:Cache miss happens when an application request data that is not in the cache, so a disk readis necessary.

    Cache reload:

    Cache reload happens when application request data that was in the cache, but aged fromcache (written back to disk), so data must be read from disk into memory. A memory cache isa fixed chunk of memory that does not grow or shrink. Most Recently Used (MRU)/LeastRecently Used (LRU) caching algorithm is used to keep the most frequently used data blocksin memory and minimize number of cache miss or reload.

    Cache hit ratio is calculated to find out the performance of different memory areas of Oracleserver running Modes.

    Page | 17

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    18/35

    Calculating size of SGA and its Components

    > select sum(value/(1024*1024)) SGA_mb from v$sga;

    SGA_MB164

    Total size of SGA is 164 mb.

    > show parametersga_max_size

    NAME TYPE VALUEsga_max_size big integer 164M

    > show parameterlog_buffer;

    NAME TYPE VALUElog_buffer integer 1048576

    > select name, value size_kb, to_char(value/(1024*1024),999.99) size_mbfrom v$sga;

    NAME SIZE_KB SIZE_MBFixed Size 787988 .75 -- instance background processesVariable Size 144964076 138.25 -- shared pool, large pool, and java poolDatabase Buffers 25165824 24.00 -- dataRedo Buffers 1048576 1.00 -- transactions

    Variable space (144964076) is composed ofshared pool, large pool, and java pool,database buffer cache is 25165824, the redo log 1048576 and additional space (787988) thatstores information used by the instance background processes.

    Command to know the current size of different SGA Areas> select component, current_size/(1024*1024) curr_size_mb

    from v$sga_dynamic_components where current_size 0;

    COMPONENT CURR_SIZE_MBshared pool 80large pool 8

    java pool 48DEFAULT buffer cache 24

    Page | 18

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    19/35

    > select name, valuefrom v$parameter

    where name in ('java_pool_size', 'sga_max_size', 'large_pool_size','log_buffer', 'shared_pool_size', 'sort_area_size');

    NAME VALUEsga_max_size 171966464shared_pool_size 83886080large_pool_size 8388608

    java_pool_size 50331648log_buffer 1048576sort_area_size 65536

    > select pool, sum(bytes) "size"from v$sgastat where pool = 'shared pool' group by pool;

    POOL sizeshared pool 83886080

    > select name, to_char(bytes/(1024*1024),999.99) size_MBfrom v$sgastatwhere name in ('buffer_cache', 'library cache', 'log_buffer', 'sql area');

    NAME SIZE_MBbuffer_cache 24.00log_buffer 1.00sql area 8.56library cache 10.65

    Page | 19

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    20/35

    > select pool Name, sum(bytes)/(1024*1024) Size_MBfrom v$sgastatwhere pool in ('java pool','large pool','shared pool') group by pool

    unionselect name, value/(1024*1024) size_MB

    from v$sga where name in ('Database Buffers','Redo Buffers');

    NAME SIZE_MBDatabase Buffers 24Redo Buffers 1

    java pool 48large pool 8shared pool 80

    > select substr(name,1,25) Name, value/(1024*1024) size_MBfrom v$parameterwhere name in

    ('java_pool_size', 'large_pool_size','log_buffer', shared_pool_size', 'db_cache_size' );

    NAME SIZE_MBshared_pool_size 80large_pool_size 8

    java_pool_size 48

    db_cache_size 24log_buffer 1

    Page | 20

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    21/35

    Oracle Physical Structures

    The physical files are made up of control files, datafiles, and redo log files. Additional filesthat are associated with the Oracle database are initialization file, trace file, alert log files,password file and any archived log files.

    File Name Information contained

    Initialization Listing of configuration parameters for the instance and the database.

    Control Location of other physical files, database name, database block size,database character set, and optionally recovery information

    Datafile Data blocks from all database segments. (data and metadata)

    Redo Log Record of all changes made to the database and used for recovery.

    Archived Log Copy of the contents of previous online Redo Los.

    Password Users information who have been granted SYSDBA or SYSOPERprivileges.

    Alert Log Informational and error messages generated by database activity.

    Trace Informational and error messages generated by users or background processes.

    Oracle Database

    An instance is a temporary structure, but the Oracle database is made up of a set of physicalfiles that reside on the host servers disk drives. These files are called:

    1. control file2. data files3. redo logs

    Additional physical files that are associated with the Oracle database, but are not technicallypart of the database are pfile/spfile, any archive log files and password file.

    Page | 21

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    22/35

    Initialization file (pfile / spfile)

    When we start server, PFILE.ORA file is read and initializes parameters and thememory areas. This is a text file and can be read in any standard text editor. This fileis known as PFILE. There are 280+ different documented parameters in Oracle.Oracle recommends that you set only about 30 basic initialization parameters

    manually.From Oracle9 version, Oracle introduces Server Parameter (SP) files also known asSPFile (server parameter file) located in same directory as pfile.SPFile can not be edited by standard text editor. It is created from standard PFILEand modified by ALTER SYSTEM command. Command can change the value of aparameter for the life of instance, or across a shutdown and start or both. The SP filesare named like spfile_SID.ora. The SP file will automatically incorporate any changesmade dynamically via ALTER SYSTEM commands.A pfile.ora file will not reflect any dynamic system changes unless they are manuallyadded to the file. Unless the instance is specially started using the STARTUP PFILE

    option with an existing pfile.ora, the values contained in the spfile.ora , not the pfile.orawill be used to determine the instance parameters. Basic information in initializationfile is:

    Different Buffer size Control file location Archive mode option Different dump file destination Rollback segment management option No of users can connect

    Parameter / Default DescriptionDB_CACHE_SIZE Caches segment data from tables, indexes etc.SHARED_POOL_SIZE Caches SQL and PL/SQL statements and data dictionaryLOG_BUFFER Caches transaction informationLARGE_POOL_SIZE Buffers I/O server processes and backup and recoveryJAVA_POOL_SIZE Buffer Java state information b/w database calls java comp.

    Comparision of Pfiles and Spfiles

    PFile SPFile

    Text file Binary file

    Called initinstance_name.ora Called spfileinstance_name.ora Can be created from an SPFile Can be created from PFile

    >create pfile from spfile; >create spfile from pfile;

    After changes in pfile, instance must be Most changes to spfile can be dynamic.Shut down and restarted before it takes effect.

    Initialization file is found in directory will be %oracle_base%\admin\SID\pfile.For Oracle9 database on college server the file name is c:\oracle\admin\oracle\database\pfile\pfile.oraFor oracle10g database on college server the file name is $oracle_home%/database/spfileo10g.ora

    Page | 22

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    23/35

    Displays parameter values in the initialization file.> show parameters

    Show a specific parameter vale of initialization file.> show parameters db_block_size

    NAME TYPE VALUEdb_block_size integer 8192

    Parameter value can also be get from v$parameter view.Display the control_files parameter value.> select name, value from v$parameterwhere name = control_files;

    Displays database block parameter value.> select name, value from v$parameter where name = 'db_block_size';

    Certain parameters can be changed dynamically by ALTER SESSION / ALTER SYSTEMcommand. A value of IMMEDIATE indicates that the parameter can be dynamically changedby ALTER command. A value of DEFERRED indicate that the change does not take effectuntil a new session is started. By using spfile, DBA has more flexibility as to when parametertakes effect in the instance.Change log buffer size to 40m> alter system set log_buffer=40m;

    Change the default date format to DD-MM-YYYY format> alter system set nls_date_format=dd-mm-yyyy;

    Change the session to English output if it is not English.> alter session set nls_language=ENGLISH;

    Change the format of sort to Arabic during the session.> alter session set nls_sort = ARABIC;

    Sort the attribute cename to Arabic format if default is other than Arabic.> select cno, cname, cename

    from customers order by nlssort(cename,NLS_SORT=ARABIC);

    Change the default datafile location for new datafiles.

    > alter session set db_create_file_dest = e:\oracle\datafiles;

    Change the max dump file size to 20000 bytes and will take effect when we restart the OracleServer after shutting down.> alter system set max_dump_file_size=20000 scope=spfilescope clause are:memory = effect is life of current instancespfile = new value takes effect when instance shutdown and startboth [DEFAULT] = for current instance across shutdown and restart

    Page | 23

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    24/35

    Control FilesControl files are critical components of the database because they store important

    information. The name of database The name, location, and sizes of the data files and redo log files. Information to recoverthe database in the case of a failure. Latest SCN (System Change Number)

    Last LSN (log switch number)

    The controlfiles are created when the database is created in the locations specified in thecontrol_files parameter in the parameter file. Oracle used CKPT process to automaticallyupdate each of these files as needed, keeping the contents of all copies of the controlfilesynchronized. You can use the view v$controlfile to display the names and locations of all the

    controlfiles.Controlfile is used to mount the database. Minimun one controlfile is needed but for safetyoracle create three controlfile. We can create more if we want.Minimum one controlfile isneeded but default value is three.

    Following command will display how many control files the database has.> select name from v$controlfile;> show parameter control_files;

    DatafilesData files are the physical files that actually store the data that has been inserted into eachtable in the database. Datafiles are the physical structure behind another database storagearea called tablespace. A tablespace is a logical storage unit within the database. By defaultOracle 10g must have at least three tablespaces. You can use v$tablespace and v$datafileviews to display their information.

    Required Tablespaces

    Tablespace Name DescriptionSYSTEM Stores the data dictionary tables and PL/SQL code.SYSAUX Stores segments used for databasae options such as the Automatic

    Workload Repository, Online Analytical Processing (OLAP), and Spatial.TEMP used for performing large sort operations.

    Common Tablespaces

    Tablespace Name DescriptionTOOLS Used to store segments for nonapplication management tools.USERS Used as default tablespace for database users.UNDOTBS1 used to store information for read consistency and recovery purposes.

    Page | 24

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    25/35

    Beyond the six mentioned tablespaces listed above, production databases often have manymore tablespaces for storing application segments. For each of the tablespace, there must beat least one datafile. Some tablespaces may be composed of several datafiles formanagement or performance reasons.

    Following command displays the name of tablespaces.> select tablespace_name from dba_tablespaces;

    Following command displays the datafiles and the corresponding tablespace they belong.> select tablespace_name, file_name from dba_data_file order by tablespace_name;

    When a user performs a SQL operation on a table, the users server process copies theaffected data from the datafile into the database buffer cache in the SGA. If the user hasperformed a committed transaction that modified that data, the DBWn ultimately writes themodified data blocks to the datafiles.

    When does the Database writer (DBWn) write?1. A server process has searched too long for a free buffer when reading a buffer into thebuffer cache.2. The number of modified and committed but unwritten buffers in the database buffercache is too large.

    3. At database checkpoint event.4. The instance is shutdown using any method other than shutdown abort.5. A tablespace is placed into backup mode.6. A tablespace is taken offline or change to read only mode.7. A segment is dropped.

    Page | 25

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    26/35

    Redo Log FilesWhen a user performs a transaction in the database, the information needed to reproducethis transaction in the event of a database failure is automatically recorded in the redo log

    buffer. The contents of the redo log buffer are ultimately written to the redo log files by theLGWR process. Redo logs are usually multiplexed or copied. Collectively, these sets of redologs are referred to as redo log groups. Each multiplexed file with in the group is called aredo log member. Oracle writes to all members of redo log group to keep the files in sync.Each redo log group must be composed of one or more members. Each database must havea minimum of two redo log groups because redo logs are used in a circular fashion.

    When a user performs a DML activity on the database, the recovery information for thetransaction is written to the redo log buffer by user server process. LGWR eventually writesthis recovery information to the active redo log group until that group is filled. Once theCURRENT log fills with transaction information, LGWR switches to the next redo log until that

    group fills with transaction information and so on. When the last redo log is used, LGWRwraps around and starts using the first redo log again.

    Following command displays all redo log groups information.> select group#, members, status,bytes from v$log;

    Following command displays all members name and their group#.> select group#, member from v$logfile order by group#;

    When does the Log writer (LWGr) write?

    1. Every three seconds

    2. A user commits a transaction.3. The redo log buffer is one-third full.4. The redo log buffer contains 1mb worth of redo information (changes).5. Before the DBWn process whenever a database checkpoint occurs.

    When LGWR wraps around from the last redo log back to the first redo log, any recoveryinformation previously stored in the first redo log group is overwritten and therefore no longeravailable for recovery purpose. However, if the database is running in archive log mode, thecontents of these previously used logs are copied to a secondary location before the log isreused. It is the job of the ARCn process to copy the contents of the redo log to the archivelocation. These copies of the old redo log entries are called archive logs.

    In the figure, the first redo log group has been filled, and LGWR has moved/switch to on toredo log group 2 from redo log group 1. As soon as LGWR switches from redo log group 1 toredo log group 2, the ARCn process starts copying the contents of the redo log group 1 to thearchive log file location as mentioned in the parameter file. Once the first redo log group issafely archived, LGWR is free to wrap around and reuse the first redo log group once redolog group 3 is filled.

    Page | 26

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    27/35

    The Alert LogThe Oracle alert log records information and error messages for a variety of activities that

    have occurred against the database during its operation. The alert log is constantly appendedto while the database is in operation. If left unmanaged, it can grow very large. Oracleautomatically creates a new alert log if the prior was deleted or renamed. The informationhelps in tuning the database.

    Common alert messages related to performance and Tuning are

    Unable to extend temp segment by n in tablespace x

    Unable to extend table x by n in tablespace x

    Unable to extend Rollback segment x by string in tablespace x

    Max # extents n reached in table x

    Checkpoint not completed

    Thread n advanced to log sequence n ( not indicate a performance problem)

    The alert log is found in the directory specified by the parameterBACKGROUND_DUMP_DEST.

    Page | 27

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    28/35

    The Trace FilesOracle trace files contain session information for the process that created them. Trace filescan be created by the oracle background process, through the use of pfile.ora trace events or

    by tracing user Server Processes.

    Background Trace filesBackground process trace files incorporate the name of the background process thatgenerated them in the trace file name.Process Name Windows System Trace File NameProcess Monitor (PMON) sidPMON.trcSystem Monitor sidSMON.trcDatabase Writer sidDBW0.trcLog Writer sidLGWR.trcCheckpoint Process sidCKPT.trc

    Archive Process sidARC0.trc

    Event TracingThe database event is a specific action or activity that occurs in the database. Oracle hasspecial option that you can configure to enable the collection of detailed tracing informationfor particular database event. By default, most database events do not cause the creation oftrace files. However, some database events can be forced to create a trace file of theiractivities you wish to trace.Tracing of these events is usually done at the instance level by adding new lines to pfile.ora.Generally you may be asked to do event tracing by the Oracle Worldwide Support (OWS) aspart of trouble shooting.

    The background process and EVENT trace files are found in the directory specified byBACKGROUND_DUMP_DEST parameter. Systems those follow OFA model this directorywill be %oracle_base%\admin\SID\bdump on windows 2000.Tracing of these events is usually done at the instance level by adding new lines to thepfile.ora. If several events are being added to the pfile.ora, they should be grouped togetherand commented appropriately. The spfile.ora looks like this:

    EVENT=10046 trace name context forever, level 12

    >alter system set event = "10046 trace name context forever, level 12"

    The double quotes are part of the syntax of this parameter.

    The event to be traced, designated by a number.

    Te level to which tracing will be performed.

    OWS personnel will provide you with these numeric values when the need for using traceevents arises.

    Page | 28

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    29/35

    User Trace filesUser Process Trace files incorporate by OS process identifier in the trace file. An examplecan be ora00776.trc. Query against the V$PROCESS and V$SESSION views can be

    performed to identify which user generated a particular trace file.

    >select s.username, p.spidfrom v$session s, v$process pwhere s.paddr = p.addrand p.background is null;

    USERNAME SPIDScott 2922Najm 3088

    Use SCOTT tracing information can be found in ora02922.trc file.

    The User trace files are found in the directory specified by USER_DUMP_DEST parameter.

    Page | 29

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    30/35

    Activating Instance-Level Tracing(background processes tracing)By setting SQL_TRACE=TRUEin pfile.ora, all processes against the instance will create theirown trace files. It creates a great deal of overhead against the system, so care must betaken. The default value for the parameter is FALSE.

    Activating User-Level Self TracingA user can turn SQL tracing ON or OFF in their own session by following SQL command.

    Command to start the tracing process> alter session set SQL_TRACE=TRUE

    Command to end the tracing process> alter session set SQL_TRACE=FALSE

    Activating User-Level DBA Tracing

    In general most applications do not provide user with a mechanism for tracing SQLcommands from within the applications. A DBA can use Oracle supplied procedures to startand stop user tracing. To activate tracing as a DBA the procedure need user system identifier(SID) and serial number (serial#) values from the V$SESSION view.

    > select username, sid, serial#from v$session where username = NAJM;

    USERNAME SID SERIAL#NAJM 20 2999

    Execute command after logging on as SYS.> execute sys.dbms_system.set_sql_trace_in_session (20, 2999, TRUE);

    Managing Trace File SizeOnce tracing is activated in a users session, every action the user takes against the instanceis included in the trace file output. Trace can grow if tracing is left on for an extended periodof time. The pfile.ora parameter MAX_DUMP_FILE_SIZE allows you to limit the size to whicha user trace file can grow.

    Parameter specification Resulting maximum size of user tracemax_dump_file_size=10000 10000 OS blocksmax_dump_file_size=unlimited No limit on file size [DEFAULT]

    Page | 30

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    31/35

    Password fileThe physical file used by Oracle to authenticate database users who are connecting withSYSDBA orSYSOPER privileges.

    Steps to create password authentication file1. Use ORAPWD utility with SYS password2. Set REMOTE_LOGIN_PASSWORDFILEparameter EXCLUSIVE/SHARED/NONE

    3. Grant users SYSDBA / SYSOPER privileges. When these privileges are granted toany user, he is added to file.

    Values forREMOTE_LOGIN_PASSWORDFILE parameterEXCLUSIVE = file is used for one database only. SYS or other users with SYSDBA or

    SYSOPER privileges entries will be made.

    SHARED = share among multiple databases. Only SYS can work.

    If connected as SYSDBA connected to SYS schemaIf connected as SYSOPER connected to PUBLIC schema.NONE = Oracle ignores the password file.

    Command to create passward file by ORAPWD unilityC:\> orapwd file= password= entries=

    File = name of password filePassword = password of SYSEntries = max no of users entriesNo space around = signFile is stored in dbs directory of oracle home

    C:\> orapwd file=c:\oracle\pwd.ora entries=10 password=syspwd

    Entries in the file cannot be modified. To change the entries we must delete and recreate thepassword file.

    Information of password file can be viewed from v$pwfile_user dynamic view.> select username, sysdba,sysoper from v$pwfile_users;

    USERNAME SYSDB SYSOPSYS TRUE TRUENAJM TRUE FALSE

    Page | 31

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    32/35

    User SessionA user session is stared when database connection is made. Session is available as long asuser is connected to the database. An ID is assigned to each session. Session identifier (SID)and serial# uniquely identifies each session. The serial# guarantees that commands are

    applied to the correct session object, if the session end and another session begins with thesame SID.

    Display all current sessions information.> select username, sid, serial# from v$session;

    Display all session but not Oracle runing sessions.> select sid, serial#, username, status, machine

    from v$session where username is not null;

    Display user NAJM session information.

    > select username, sid, serial#, status, programfrom v$session where username = NAJM;

    USERNAME SID SERIAL#NAJM 5 3

    How to kill/disconnect a user sessionsFollowing command will kill username NAJM session for which we found SID and SERIAL#from previous command>alter system kill session 5,3;

    >alter system kill session 5,3 immediate;

    >alter system disconnect session 5,3 post_transaction;

    When you kill a session, Oracle terminates the session to prevent any more SQL execution.Statement is terminates when session is terminated and all changes are rolled back. Sessionlock and other resources are released.

    Ifinactive session is killed, Oracle terminates the session and mark the status as killedSubsequently when user tries to use session, error is returned to user and sessioninformation is removed from v$session

    Ifactive session is killed with IMMEDIATE option, ongoing transaction is rolled back andrelease session locks.

    Page | 32

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    33/35

    CheckpointPeriodically Oracle perform checkpoint. DBWn writes all modified data blocks in the instance

    buffer cache back to Data Files that contains those blocks. Checkpoint indicates how much oftransaction log entries oracle must apply if simple server crash occurs.

    1. Each log switch perform checkpoint2. When tablespace goes offline. Checkpoints for the blocks of the tablespace.3. Time based checkpoint4. Manual checkpoints

    >alter system switch logfile;>alter system checkpoint;

    Log_checkpoint_timeout = time between two consecutive checkpoints

    Log_checkpoint_interval =[(log file size /db_block_size)*(db_block_size/os block size)] / # of desired checkpoints b/w log switch

    Commit

    1. Releases the Locks2. Rollback segment is freed3. Trans move from log buffer to log file.

    Rollback1. Move old / rolled back information from rollback segment back to memory2. Releases the Locks3. Rollback segment is freed

    Page | 33

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    34/35

    Connection Request Failure reasons

    A connection request may fail for many reasons. Here are a few of most common reasons forconnection failure.

    Rejection due to Invalid Net Service NameIf the net service name cannot be resolves, you will receive an error. This code shows that

    the user will receive an error because of this rejection.

    ERROR:ORA-12154: TNS:could not resolve service name

    If Host Machine name is incorrect in Net Service

    ERROR:ORA-12545: Connect failed because target host or object does not exist

    The listener process is not runningIf the listener process is not available, the connection will fail. The following code shows theresult from the situation.

    ERROR:ORA-12541: TNS:no listener

    The Service Name supplied is invalidIf the user supplies a service name the listener is not listening for, the listener will return anerror. The following code shows the result of connecting with an invalid service name.

    ERROR:ORA-12514 TNS:listener could not resolve SERVICE_NAME given in correct descriptor

    The Oracle Instance is not runningThe Oracle instance that the user wants to connect to is not available, The connection will berejected. Following is an example of this occurrence:

    ERROR:ORA-01034: ORACLE not available

    The user supplied an Invalid User ID or PasswordIf the user supplied an invalid User ID or Password, the connection will be rejected. In thiscase the server process on the Oracle Server is created. The server process validates theUser ID and the Password against the known users and Passwords on the database. If nomatch is found, the connection fails.

    ERROR:ORA-01017: invalid username/password; logon denied

    Page | 34

  • 8/7/2019 IS337 Doc Spring 2010 CH2

    35/35

    SQL Statement Execution StepsWhen a statement is send to Oracle database server, Oracle server process

    First converts the characters in the SQL statement to ASCII equivalent numeric codes.- Next, this string of ASCII code is passed through hashing algorithm, which in

    turn produces a single hashed value.- The User Server process then checks to see if that hashed value already exists

    in the SQL Area of the Shared Pool.- If it does, the Users Server Process uses the cached version of the statement

    to execute the statement.- If the hashed value does not exist in the Shared Pool, The Users Server

    Process goes about the process ofparsing the statement, and then executesit.

    The Parse step must complete the following tasks:1. Check the statement for syntactic corrections.2. Names and structures of the reference objects are checked against the data

    dictionary.3. Gather statistic regarding the objects referenced from data dictionary.4. Prepare and select an execution plan from available plans.5. Determine the security of the referenced objects.6. Generate a compiled version of statement (P-Code)

    Instance Recovery at Instance Startup (SMON).Whenever a commit is executed by a user the relevant transaction is assigned a SCN andwritten to Redo Log file from Log Buffer and the transaction number is updated in the Controlfile.

    1. At Checkpoint DBWr writes dirty blocks of committed transactions from data buffer todata files.2. Checkpoint process CKPT, updates the header of all the data files with the last

    Transaction number SCN whose data is moved from data buffer to data files.3. At the server startup SMON compares the SCN in the Control files with the SCN of allthe data files. If any transaction is missing, SMON will run that transaction and willsynchronize the SCN of Data files with that of Control files and the database reached toconsistent state.