Oracle DBA Notes
Oracle DBA Notes
NOTES:
Database Administration
(ORACLE 8)
Oracle Architectural Components
Users can be connected to an Oracle server in various configurations,
including a direct host based connection such as UNIX telnet session, a
two-tiered client-server type connection such as pc-connection to a UNIX
or NT server using SQLNet or a 3-tier configuration where the client
machine is connected to an application server which in turn is connected
to the Oracle database server.
SGA: (System Global Area, sometimes call the Shared Global Area) is
a group of shared memory structures. The SGA is made up of the
following structures:
1) The Shared Pool - Comprised of the Library Cache (also know as the Shared SQL Area) and the Row Cach
(also know as the Dictionary Cache or Data Dictionary Cache). Sized specified by SHARED_POOL_SIZ
variable in the parameter file.
• Library Cache - Contains the following for the most recently used
SQL statement: Statement text, parsed code (parse tree), and
execution plan.
Page 1
PIA Training Centre Prime Communications
2) Database Buffer Cache - Contains x amount of database buffers as specified by the DB_BLOCK_BUFFER
initialization parameter in the size of DB_BLOCK_SIZE. Also contains the dirty buffer write queue, whic
holds dirty block buffers (i.e. already written to) until they can be written to disk. Least recently used(LRU
algorithm used to decide which buffers to move out of the buffer cache to make room for new buffers to be read in
3) Redo Log Buffer - The size of the redo log buffer is specified by the LOG_BUFFER initialization paramete
Circular buffer containing information about changes made to the database. Records are written from the redo lo
buffer to the online redo log files by the LGWR process.
There are four mandatory processes. If any of these processes fail the
instance will crash and have to be restarted!
PMON (Process Monitor)
• Cleans up abnormally terminated user sessions
• Rolls back any uncommitted transactions
• Releases locks held by a terminated process
• Frees SGA resources allocated to the failed process
• Restarts failed shared server and dispatcher processes
• Identified deadlocks
SMON (System Monitor)
• Performs automatic instance recovery
• Reclaims space used by temporary segments no longer in use
• Merges contiguous areas of free space in the datafiles. Known as
defragging or coalescing.
DBWR (Database Writer)
• Writes all changed (i.e. dirty) buffers to datafiles.
• Uses a LRU (least recently used) algorithm to keep most recently
used blocks in memory.
• Defers writes for I/O optimization.
Page 2
PIA Training Centre Prime Communications
Page 3
PIA Training Centre Prime Communications
• Record all changes made to the database and are used for data
recovery.
• Written in a circular fashion.
• There must be at least 2 redo log groups.
• Each redo log group should contain the same number of members.
Control Files:
• A binary file that describes the structure of the database.
• Required to mount, open, and access the database.
• Synchronization info needed for recovery is stored in the control file
• Recommended configuration is a min of 2 control files on separate
disks.
Parameter File:
• Used to size the SGA and locate the control files at instance start up.
• Contains all the database initialization parameters.
Password File:
• Stores passwords for users with admin privileges.
• Used only with database authentication, not OS level authentication.
• V$PWFILE_USERS tells what users are in the password file.
• Naming convention = orapw<sid>.pwd
Command Syntax: ORAPWD file=... password =.. entries= ...
REMOTE_LOGIN_PASSWORDFILE parameter values:
1. NONE - no unsecured privileged sessions because no password file
exists.
2. EXCLUSIVE - Password file used for that instance only. Needed
for remote-nonsecure connections.
3. SHARED - password file only allows access for admin option by
SYS and the DBA using CONNECT INTERNAL.
If a secure connection can be obtained you can use OS authentication. If
no secure connection is possible you must use oracle method.
Archived redo log files:
• Offline versions of the redo log files.
• Used for database recovery from media failure
Alert File:
• Logs all internal (ORA-600), block corruption (ORA-1578), and
deadlock (ORA-60) errors.
• Logs all DDL and Server Manager commands such as STARTUP,
SHUTDOWN, ARCHIVE LOG and RECOVER.
• Logs the values of all non-default initialization parameters at the time
of database and instance startup.
• Located in destination specified by
BACKGROUND_DUMP_DEST.
• Should be checked at least daily.
Trace Files:
• Contains internal errors detected by server or background
processes.
• If dumped by a background process the file is located in destination
specified by initialization parameter
BACKGROUND_DUMP_DEST.
• If dumped by server process the file located in destination specified
by initialization parameter USER_DUMP_DEST.
Page 4
PIA Training Centre Prime Communications
This step is only performed for SELECTs. Not for INSERT, UPDATE,
or DELETEs.
5) FETCH
For SELECT only. Returns dataset into BIND variables.
Criteria for reuse of execution plan:
1. Current SQL statement must be identical to statement already parsed,
including upper/lower case, white space, and commas.
2. Referenced objects are identical.
3. The types and names of variables are identical.
4. The parsed execution plan must be in the shared pool at the same
time the current sql statement trying to reuse it is looking for it.
Page 5
PIA Training Centre Prime Communications
Server Manager Line Mode - Command utility used to perform all DBA tasks. Good for running unatten
"batch" operations because it can be executed from within a script. Can execute all SQL or PL/SQL statements.
backslash "\" is the "server manager command" line-continuation character. No continuation character is needed
multiple line SQL statements. Execute a multiple line SQL statement using a semi-colon or a forward slash "/" on
last line by it self. Can use @ command to run a script.
Some server manager commands that do not require a connection to the database are: EXIT REMARK SET SHO
SPOOL. Know all the SHOW commands and what they display.
Oracle Enterprise Manager - GUI used to tune, monitor and administer databases. Contains various compone
such as the OEM Console which contains a menu, launch palette, navigator, map, job system, and event system.
OEM Repository is a special set of tables used by OEM within a database for each administrator. Standard O
applications include the Instance Manager, Schema Manager, Security Manager, Storage Manager, SQL Worksh
Backup Manager, and Data Manager. Be sure you know what each of these modules does! A Performance Pack
also be purchased with OEM. The Performance Pack contains the following additional modules: Top Sess
Monitor, Lock Manager, Advanced Events, Tablespace Manager, Trace, and Expert.
SQLLoader - Oracle's tool for loading data from "flat" text files into the Oracle database.
Import/Export Utility - Oracles tool for exporting and importing data to and from Oracle-formatted files.
Password Utility File - Used to password file for a database.
Page 6
PIA Training Centre Prime Communications
O/S Authentication
On UNIX user must be a member of the UNIX dba group.
Use when a secure connection is not possible.
Set REMOTE_LOGIN_PASSWORDFILE parameter to NONE. This is
the default for this parameter.
CONNECT / AS (SYSDBA or SYSOPER)
**See Oracle notes for NT "group" and "userid" set up requirements to
use O/S authentication. Oracle8 no longer support setting the
DBA_AUTHORIZATION=BYPASS parameter in the registry to allow
connections without using a password.
Password Authentication
Create the password file using ORAPWD on UNIX or ORAPWD80 on
NT.
Set REMOTE_LOGIN_PASSWORDFILE parameter to EXCLUSIVE
(only one instance can use the password file and the file contains other
userids besides SYS and SYSTEM) or SHARED (more than one instance
can use the password file. SYS and INTERNAL are the only users known
to the password file)..
Parameter File
Referred to as the init<SID>.ora file. If sid=orcl then file name =
initorcl.ora . The file is read at time of system startup. Changes to the
parameter file will take effect only after the database has been stopped
and restarted.
Default Location in UNIX = /$ORACLE_HOME/dbs. Default location
in NT = %ORACLE_HOME%\database.
OEM needs to have a local copy of the parameters file to start a remote
instance or db. However, OEM can also store multiple database startup
configurations in it's registry and this removes the need to have versions
of multiple parameter files stored on the machine acting as the OEM
console.
For the test, be sure and know the uses and rules for setting the various
parameters that live in the init<sid>.ora file. You should know and be very
familiar with the following parameters: BACKGROUND_DUMP_DEST
, COMPATIBLE , CONTROL_FILES , DB_BLOCK_BUFFERS ,
DB_NAME , SHARED_POOL_SIZE , USER_DUMP_DEST , IFILE ,
LOG_BUFFER , MAX_DUMP_FILE_SIZE , PROCESSES ,
SQL_TRACE , TIMED_STATISTICS .
Page 7
PIA Training Centre Prime Communications
• OPEN - All files opened as described by the control file for this
instance. Used for database access for all users. Datafiles and redo
log files are verified and opened.
TABLE for Database Startup Stages:
Stages What Happens When Used Tasks Involved
Starting Instance is Used at the time of • Reads the parameter file init<SID>.ora
an started either the creation of • Allocates the SGA
Instance the database or the • Starts the background processes
recreation of control • Opens the TRACE and ALERT files
files
Mounting Instance is Used while performing • Database associated with previously
the started and the specific Database started instance
Database Database is maintenance tasks • Locate the control files
mounted • Open the control files
• Reads the control files to obtain the
names and status of the data files and
the redo log files
Open the Instance is Used when Database is • Oracle verify that the data files and the
Database started, Database to be accessed by users redo log files can be opened
is mounted and • Oracle opens the data files and the
opened redo log files
• Oracle returns an error and does not
open the database if any of the data
files and redo log files are not present
• Oracle checks the database
consistency
• SMON initiates instance recovery
Instance Recovery
SMON will automatically perform instance recovery when opening up the
database if database crashed or was shut down using abort.
1. Rolls forward txns recorded in online redo log that have not been
recorded in the data files.
2. Opens database before all roll forward txns have been applied.
3. SMON rolls back any uncommitted txns.
Database Shutdown Stages:
• CLOSE - Write buffer cache and redo buffer changes, close online
redo log and data files. Control file remains open.
• DISMOUNT - Control files are closed.
• SHUTDOWN - Trace and Alert files closed, SGA deallocated,
background processes are stopped.
Additional Database Startup "Modes"
• Should always issue SHUTDOWN NORMAL and STARTUP
NORMAL afterwards.
Page 8
PIA Training Centre Prime Communications
Page 9
PIA Training Centre Prime Communications
Page 10
PIA Training Centre Prime Communications
Sequential writes to the current online redo log by the LGWR process
occur when either of the following happen:
1. A commit occurs
2. redo log buffer poll gets one-third full
3. A LGWR timeout occurs - one every 3 seconds.
Page 11
PIA Training Centre Prime Communications
4. Before the DBWR process writes dirty blocks from the db buffer
cache to the data files.
Page 12
PIA Training Centre Prime Communications
Page 13
PIA Training Centre Prime Communications
Some defaults:
Min size of INITIAL is 2*db_block_size. Default size of INITIAL = 5 db
blocks.
Min size of NEXT is one block. Default is 5 db blocks.
The min and default for MINEXTENTS = 1.
Min value of PCTINCREASE = 0 and the default is 50.
Min value of MAXEXTENTS=1 default is a function of the db block
size.
Know how to make a tablespace temporary.
Know how to add a data file to a tablespace.
Know how to use the autoextend feature.
Know how to change the size of a data file manually.
Know how to change t he storage settings of a tablespace. ALTER
TABLESPACE MINIMUM EXTENT to change the minimum extent
allocated.
Know how to take a tablespace offline.
Some ALTER TABLESPACE offline options:
Types of segments:
1. Table Segment - Unclustered or nonpartitioned tables.
2. Table Partition - Data within a table can be stored in multiple
partitions and each partition can exist in a different tablespace if
desired. Each partition can have it's own storage parameters. Helps to
reduce I/O contention by distributing the table data. Requires the use
of the Oracle8 Partition option.
3. Cluster - Rows are "clustered" together based upon key column
value(s). A cluster can contain multiple tables. Is a type of data
segment. Objects in a cluster belong to the same segment and share
the same storage values.
Page 14
PIA Training Centre Prime Communications
SYSTEM tablespace.
• If a user is going to create tables in other tablespaces besides
SYSTEM at least one more rollback segment is required.
• All rollback segments should be the same size. The PCTINCREASE
storage parameter value is not allowed. Is always equal to zero (0) for
rb segs.
• Requires a minimum of 2 extents of the same size.
• Always store in their own tablesapce to avoid I/O contention! The
TABLESPACE clause is optional in a CREATE ROLLBACK
SEGMENT command. If it is not included, the rollback segment will
be created in the SYSTEM tablespace.
Page 15
PIA Training Centre Prime Communications
Page 16
PIA Training Centre Prime Communications
Page 17