This blog is a note for self learning. Some writings are done by myself and some are collected, just to keep things in a organized way.
7.30.2008
Data Dictionary Tables and Views
7.29.2008
PL/SQL Objects
Procedure: A block of PL/SQL code that is stored in the database and performs a specific action.
Function: A block of PL/SQL code that is stored in the database and returns a value when called in a SQL statement.
Package: A collection of related procedures and/or functions that perform related functions.
Trigger: A block of PL/SQL code that runs whenever an INSERT, UPDATE, or DELETE activity occurs on a table. Can also be defined to run when certain database events occur.
Datablock, Extent and Segment
Each Oracle segment is made up of contiguous chunks of storage space in the database called extents. Every segment must have at least one extent, but can have as many as 2 billion extents.
Each extent is itself made up of a collection of smaller chunks of space called Oracle database blocks. The minimum size of an extent is five database blocks.
The default size of these database blocks is set at database creation, but Oracle 10g db can use multiple block sizes within one db. The common database block sizes are 2KB, 4KB, 8KB, and 16KB.
Each database block is in turn composed of one or more operating system blocks.
SQL Limitations
-SQL also lacks looping capabilities, the ability to perform a specific SQL action for a specified number of times before stopping.
-Finally, SQL does not offer any exception-handling capabilities;
-all errors raised by SQL statements are returned directly to the user.
Background processes
The DBWn background process writes to the datafiles whenever one of the following events occurs:
--The number of modified and committed, but unwritten, buffers in the Database Buffer Cache is too large.
--At a database Checkpoint event. See Chapters 10 and 11 for information on checkpoints.
--The instance is shut down using any method other than a shutdown abort.
--A tablespace is placed into backup mode.
--A tablespace is taken offline to make it unavailable or changed to READ ONLY.
--A segment is dropped.
Log writer (LGWR):
• Every time a user commits a transaction.
• When the redo log buffer becomes one-third full.
• When the redo log buffer reaches 1 MB.
Checkpoint process (CKPT):
Process monitor (PMON):
Tracks all the other background processes. If a user process fails, PMON handles the cleanup by deallocating memory back to the SGA.
System monitor (SMON):
Handles instance recovery on instance startup, cleans up temporary segments, and consolidates free space in the datafiles.
Dirty datablocks
PGA
SGA
The size of the SGA is determined by several initialization parameters. The following parameters have the greatest effect on SGA size:
DB_CACHE_SIZE - The size of the cache of standard blocks.
LOG_BUFFER - The number of bytes allocated for the redo log buffer.
SHARED_POOL_SIZE - The size in bytes of the area devoted to shared SQL and PL/SQL statements.
LARGE_POOL_SIZE - The size of the large pool; the default is 0.
JAVA_POOL_SIZE - The size of the Java pool.
Shared pool:
The shared pool contains shared memory constructs, such as shared SQL areas, cached SQL and PL/SQL statements. It is called the shared pool because its contents are shared by all database users. The shared pool contains the library cache, the dictionary cache, and an area for control structures and character sets.
Java pool:
Optional SGA component that caches the most recently used Java objects and application code.
Large pool:
Optional SGA component that caches data for large operations, such as Shared Server or Parallel Execution.
Streams pool:
Optional SGA component that caches data from queued message requests.
Dictionary:
The data dictionary is a collection of database tables and views containing reference information about the database, its structures, and its users. Oracle accesses the data dictionary frequently during SQL statement parsing. This access is essential to the continuing operation of Oracle.
The data dictionary is accessed so often by Oracle that two special locations in memory are designated to hold dictionary data. One area is called the data dictionary cache , also known as the row cache because it holds data as rows instead of buffers (which hold entire blocks of data).
The other area in memory to hold dictionary data is the library cache.
All Oracle user processes share these two caches for access to data dictionary information.
Library cache:
Acts as a warehouse for database commands. When a user issues a command, Oracle looks in the library cache to see if a duplicate statement exists. If it does, the new statement is discarded, and the stored statement is used instead. This approach saves processing time.
Supporting Files
There are different Supporting Files:
Parameter file:
Parameter file contains a list of initialization parameters that control how certain aspects of the database instance behave. Most parameters can be modified without restarting the instance, while some require that it be shut down and restarted to pick up the new values. Also known as the initialization file.
When the Oracle database is started, one of the first things it needs to do is read the database initialization parameter file. The parameter file (init.ora) is created by the DBA and defines the overall instance configuration, such as how much memory should be allocated to the instance, the file locations, and internal optimization parameters.
Password file:
Password file Stores passwords in an encrypted format for certain privileged users who are allowed to start and stop the database. Normally, when users connect to the database, their privileges are verified from within the database itself. Since the database is unavailable when it is not running, a privileged user who is starting the database must be authenticated by some other means. The password file provides this capability by storing the privileged user’s password outside of the database.
Alert log:
Alert log Records all internal errors and information about several database operations. The DBA should check the alert log at least once a day. The alert log entry briefly describes an error and provides the name of a trace file , which contains more detailed information regarding the internal errors.
Control File
- Database name,
- Timestamp of database creation,
- Names of the database's Datafiles and online and archived redo log files,
- Datafile locations,
- Checkpoint, a record indicating the point in the redo log where all database changes prior to this point have been saved in the datafiles
- Synchronization information, and
- Recovery Manager(RMAN) backup meta-data
Without these files, the database cannot start up. If anything happens to the control files while the database is running, the database will crash. If the physical makeup of the database is altered (for example, if a new datafile or redo log file is created), then the control file is automatically modified by Oracle to reflect the change.
Oracle (or Oracle users can) multiplex the control file, allowing Oracle to write multiple copies of the control file to protect it against disaster or failure.
If the operating system supports disk mirroring, the control file can also be mirrored, allowing the O/S to write a copy of the control file to multiple disks. Every time a user mounts an Oracle database, its control file is used to identify the datafiles and online redo log files that must be opened for database operation.
The control file should be backed up whenever the structure of the database changes. Structural changes can include adding, dropping, or altering datafiles or tablespaces and adding or dropping online redo logs.
Redo log file
Redo log contains one or more copies of itself in case one of the copies becomes corrupt or is lost due to a hardware failure. Collectively, these sets of redo logs are referred to as redo log groups. Each multiplexed file within the group is called a redo log group member.
Each database must have a minimum of two redo log groups because redo logs are used in a circular fashion.
Datafiles
ADD Datafile to Tablespace:
ALTER TABLESPACE DATA02
ADD DATAFILE '/oradata1/THRP/DATA02_02.dbf'
SIZE 100M;
ALTER TABLESPACE STATE_DATA01
add datafile '/data/state_datafiles/STATE_DATA01_01.dbf'
size 1G AUTOEXTEND ON NEXT 100M;
ALTER Datafile:
ALTER database datafile '/oradata1/THRP/DATA02_02.dbf' AUTOEXTEND ON MAXSIZE 20G;
alter database datafile '/oradata1/THRP/DATA02_02.dbf' AUTOEXTEND ON NEXT 50M;
The datafiles contain all the database data. The data of logical database structures, such as tables and indexes, is physically stored in the datafiles allocated for a database. Every Oracle database has one or more physical datafiles.
The datafile is divided into smaller units called data blocks. The data of logical database structures, such as tables and indexes, is physically located in the blocks of the datafiles allocated for a database.
Datafiles hold the following characteristics:
- One or more physical datafiles form a logical database storage unit called a tablespace.
- Datafiles can have certain characteristics set to let them automatically extend when the database runs out of space.
The first block of every datafile is the header. The header includes important information such as file size, block size, tablespace, and creation timestamp. Whenever the database is opened, Oracle checks to see that the datafile header information matches the information stored in the control file. If it does not, then recovery is necessary. Oracle reads the data in a datafile during normal operation and stores it in the buffer cache.
For example, assume that a user wants to access some data in a table. If the requested information is not already in the buffer/memory cache, Oracle reads it from the appropriate datafiles and stores it in memory.
Modified or new data is not necessarily written to a datafile immediately. To reduce the amount of disk access and to increase performance, data is pooled in memory and written to the appropriate datafiles all at once, as determined by the database writer process (DBWn) background process.
7.01.2008
Oracle Architecture
1.Physical database:
----i.Data file
----ii.Redo log file
----iii.Control file
2.Instance:
---- i.Large memory area:
-------- a. System Global Area (SGA):
-------------------- 1. Database buffer cache
-------------------- 2. Redo log buffer
-------------------- 3. Shared pool
-------------------- 4. Java pool
-------------------- 5. Large pool (optional)
-------------------- 6. Streams pool
-------------------- 7. Dictionary cache:
---------------------------- Data Dictionary cache
---------------------------- Library cache
-------------------- 8. Other miscellaneous information
-------- b. Program Global Area (PGA)
-------- c. Optional Area – Software Area Code
---- ii.Set of background processes:
-------- a. Database Writer Process (DBWn)
-------- b. Log Writer Process (LGWR)
-------- c. Checkpoint Process (CKPT)
-------- d. System Monitor Process (SMON)
-------- e. Process Monitor Process (PMON)
-------- f. Recoverer Process (RECO)
-------- g. Job Queue Processes
-------- h. Archiver Processes (ARCn)
-------- i. Queue Monitor Processes (QMNn)
-------- j. Other Background Processes