Welcome Guest Donate | Search | Active Topics | Members | Log In | Register

Oracle Database and PL/SQL Tips and Techniques Options
lingy
Posted: Saturday, July 10, 2010 2:52:25 PM

Rank: Administration
Groups: Administration , Member

Joined: 5/8/2009
Posts: 1,576
Points: 5,631

Oracle Server Architecture

An Oracle server uses memory structures and processes to manage and access the database. All memory structures exist in the main memory of the computers that constitute the database system. Processes are jobs that work in the memory of these computers.

An Oracle server consists of an Oracle database and an Oracle server instance. Every time a database is started, a system global area (SGA) is allocated and Oracle background processes are started. The combination of the background processes and memory buffers is called an Oracle instance.

The architectural features discussed in this article enable the Oracle server to support:

  • Many users concurrently accessing a single database
  • The high performance required by concurrent multiuser, multiapplication database systems

Figure 1 shows a typical variation of the Oracle server memory and process structures.

Figure 1 Memory Structures and Processes of Oracle

Description of cncpt154.gif follows

Memory Structures

Oracle creates and uses memory structures to complete several jobs. For example, memory stores program code being run and data shared among users. Two basic memory structures are associated with Oracle:

  • System global area, and
  • Program global area

System Global Area

The System Global Area (SGA) is a shared memory region that contains data and control information for one Oracle instance. Oracle allocates the SGA when an instance starts and deallocates it when the instance shuts down. Each instance has its own SGA.

Users currently connected to an Oracle server share the data in the SGA. For optimal performance, the entire SGA should be as large as possible (while still fitting in real memory) to store as much data in memory as possible and to minimize disk I/O.

The information stored in the SGA is divided into several types of memory structures, including:

  • Database buffers:  store the most recently used blocks of data. The set of database buffers in an instance is the database buffer cache. The buffer cache contains modified as well as unmodified blocks. Because the most recently (and often, the most frequently) used data is kept in memory, less disk I/O is necessary, and performance is improved.
  • Redo log buffer: stores redo entries--a log of changes made to the database. The redo entries stored in the redo log buffers are written to an online redo log, which is used if database recovery is necessary. The size of the redo log is static.

  • Shared pool: contains shared memory constructs, such as shared SQL areas. A shared SQL area is required to process every unique SQL statement submitted to a database. A shared SQL area contains information such as the parse tree and execution plan for the corresponding statement. A single shared SQL area is used by multiple applications that issue the same statement, leaving more shared memory for other uses.

  • Large pool(optional): provides large memory allocations for Oracle backup and restore operations, I/O server processes, and session memory for the shared server and Oracle XA (used where transactions interact with more than one database).

  • Statement Handles or Cursors. A cursor is a handle (a name or pointer) for the memory associated with a specific statement. (Oracle Call Interface, OCI, refers to these as statement handles.) Although most Oracle users rely on automatic cursor handling of Oracle utilities, the programmatic interfaces offer application designers more control over cursors. For example, in precompiler application development, a cursor is a named resource available to a program and can be used specifically to parse SQL statements embedded within the application. Application developers can code an application so it controls the phases of SQL statement execution and thus improves application performance.

Process Architecture

A process is a "thread of control" or a mechanism in an operating system that can run a series of steps. Some operating systems use the terms job or task. A process generally has its own private memory area in which it runs.

An Oracle server has two general types of processes: user processes and Oracle processes.

User (Client) Processes

User processes are created and maintained to run the software code of an application program (such as a Pro*C/C++ program) or an Oracle tool (such as Enterprise Manager). User processes also manage communication with the server process through the program interface.

Oracle Processes

Oracle processes are invoked by other processes to perform functions on behalf of the invoking process. The different types of Oracle processes and their specific functions are discussed in the following sections.

Server Processes

Oracle creates server processes to handle requests from connected user processes. A server process communicates with the user process and interacts with Oracle to carry out requests from the associated user process. For example, if a user queries some data not already in the database buffers of the SGA, then the associated server process reads the proper data blocks from the datafiles into the SGA.

Oracle can be configured to vary the number of user processes for each server process. In a dedicated server configuration, a server process handles requests for a single user process. A shared server configuration lets many user processes share a small number of server processes, minimizing the number of server processes and maximizing the use of available system resources.

On some systems, the user and server processes are separate, while on others they are combined into a single process. If a system uses the shared server or if the user and server processes run on different machines, then the user and server processes must be separate. Client/server systems separate the user and server processes and run them on different machines.

Background Processes

Oracle creates a set of background processes for each instance. The background processes consolidate functions that would otherwise be handled by multiple Oracle programs running for each user process. They asynchronously perform I/O and monitor other Oracle process to provide increased parallelism for better performance and reliability.

Each Oracle instance can use several background processes. The names of these processes are DBWn, LGWR, CKPT, SMON, PMON, ARCn, RECO, Jnnn, Dnnn, LMS, and QMNn.

Database Writer (DBWn)

The database writer writes modified blocks from the database buffer cache to the datafiles. Although one database writer process (DBW0) is sufficient for most systems, you can configure additional processes (DBW1 through DBW9 and DBWa through DBWj) to improve write performance for a system that modifies data heavily. The initialization parameter DB_WRITER_PROCESSES specifies the number of DBWn processes.

Because Oracle uses write-ahead logging, DBWn does not need to write blocks when a transaction commits. Instead, DBWn is designed to perform batched writes with high efficiency. In the most common case, DBWn writes only when more data needs to be read into the SGA and too few database buffers are free. The least recently used data is written to the datafiles first. DBWn also performs writes for other functions, such as checkpointing.

Log Writer (LGWR)

The log writer writes redo log entries to disk. Redo log entries are generated in the redo log buffer of the SGA, and LGWR writes the redo log entries sequentially into an online redo log. If the database has a multiplexed redo log, then LGWR writes the redo log entries to a group of online redo log files.

Checkpoint (CKPT)

At specific times, all modified database buffers in the SGA are written to the datafiles by DBWn. This event is called a checkpoint. The checkpoint process is responsible for signaling DBWn at checkpoints and updating all the datafiles and control files of the database to indicate the most recent checkpoint.

System Monitor (SMON)

The system monitor performs recovery when a failed instance starts up again. With Real Application Clusters, the SMON process of one instance can perform instance recovery for other instances that have failed. SMON also cleans up temporary segments that are no longer in use and recovers terminated transactions skipped during recovery because of file-read or offline errors. These transactions are eventually recovered by SMON when the tablespace or file is brought back online. SMON also coalesces free extents in the dictionary managed tablespaces to make free space contiguous and easier to allocate.

Process Monitor (PMON)

The process monitor performs process recovery when a user process fails. PMON is responsible for cleaning up the cache and freeing resources that the process was using. PMON also checks on dispatcher and server processes and restarts them if they have failed.

Archiver (ARCn)

The archiver copies the online redo log files to archival storage after a log switch has occurred. Although a single ARCn process (ARC0) is sufficient for most systems, you can specify up to 10 ARCn processes by using the dynamic initialization parameter LOG_ARCHIVE_MAX_PROCESSES. If the workload becomes too great for the current number of ARCn processes, then LGWR automatically starts another ARCn process up to the maximum of 10 processes. ARCn is active only when a database is in ARCHIVELOG mode and automatic archiving is enabled.

Recoverer (RECO)

The recoverer is used to resolve distributed transactions that are pending due to a network or system failure in a distributed database. At timed intervals, the local RECO attempts to connect to remote databases and automatically complete the commit or rollback of the local portion of any pending distributed transactions.

Job Queue Processes (Jnnn)

Job queue processes are used for batch processing. Job queue processes are managed dynamically. This enables job queue clients to use more job queue processes when required. The resources used by the new processes are released when they are idle.

Dispatcher (Dnnn)

Dispatchers are optional background processes, present only when a shared server configuration is used. At least one dispatcher process is created for every communication protocol in use (D000, . . ., Dnnn). Each dispatcher process is responsible for routing requests from connected user processes to available shared server processes and returning the responses back to the appropriate user processes.

Lock Manager Server (LMS)

The Lock Manager Server process (LMS) is used for inter-instance locking in Real Application Clusters.

Queue Monitor (QMNn)

Queue monitors are optional background processes that monitor the message queues for Oracle Advanced Queuing. You can configure up to 10 monitor processes.

Sponsor
Posted: Saturday, July 10, 2010 2:52:25 PM


lingy
Posted: Saturday, July 10, 2010 2:58:28 PM

Rank: Administration
Groups: Administration , Member

Joined: 5/8/2009
Posts: 1,576
Points: 5,631

SQL Processing Architecture In Oracle

In Oracle, the SQL processing architecture is comprised of the following main components:

  • Parser
  • Optimizer
  • Row Source Generator
  • SQL Execution

The following figure illustrates the SQL processing architecture:


 

The parser, the optimizer, and the row source generator form the SQL Compiler. This compiles the SQL statements into a shared cursor. Associated with the shared cursor is the execution plan.

Parser

The parser performs two functions:

  • Syntax analysis: This checks SQL statements for correct syntax.
  • Semantic analysis: This checks, for example, that the current database objects and object attributes referenced are correct.
Optimizer

The optimizer is the heart of the SQL processing engine. The Oracle server provides two methods of optimization: rule-based optimizer (RBO) and cost-based optimizer (CBO).

Row Source Generator

The row source generator receives the optimal plan from the optimizer. It outputs the execution plan for the SQL statement. The execution plan is a collection of row sources structured in the form of a tree. A row source is an iterative control structure. It processes a set of rows, one row at a time, in an iterated manner. A row source produces a row set.

SQL Execution

SQL execution is the component that operates on the execution plan associated with a SQL statement. It then produces the results of the query.

lingy
Posted: Saturday, July 10, 2010 3:04:47 PM

Rank: Administration
Groups: Administration , Member

Joined: 5/8/2009
Posts: 1,576
Points: 5,631

Identifying Oracle Database Software Release

As many as five numbers may be required to fully identify a release. To understand the release level nomenclature used by Oracle, examine the following example of an Oracle database server labeled "Release 9.2.0.1.0."

Description of admin002.gif follows

Major Database Release Number

This is the most general identifier. It represents a major new edition (or version) of the software that contains significant new functionality.

Database Maintenance Release Number

This digit represents a maintenance release level. Some new features may also be included.

Application Server Release Number

This digit reflects the release level of the Oracle9i Application Server (Oracle9iAS).

Component Specific Release Number

This digit identifies a release level specific to a component. Different components can have different numbers in this position depending upon, for example, component patch sets or interim releases.

Platform Specific Release Number

This digit identifies a platform specific release. Usually this is a patch set. Where different platforms require the equivalent patch set, this digit will be the same across the effected platforms.

--------------------------------------------------------------------------------
Note:
Starting with release 9.2, maintenance releases of Oracle are denoted by a change to the second digit of a release number. In previous releases, the third digit indicated a particular maintenance release.

-------------------------------------------------------------------------------

Checking Your Current Release Number

To identify the release of the Oracle database server that is currently installed and to see the release levels of other Oracle components you are using, query the data dictionary view PRODUCT_COMPONENT_VERSION. A sample query is shown below.

SQL>SELECT * FROM PRODUCT_COMPONENT_VERSION;
PRODUCT                       VERSION    STATUS            
----------------------------- ---------- ------------  
NLSRTL                        9.2.0.1.0  Production       
Oracle9i Enterprise Edition   9.2.0.1.0  Production       
PL/SQL                        9.2.0.1.0  Production       
TNS for Solaris:              9.2.0.1.0  Production

Optionally, you can query the V$VERSION view to see component-level information.

SQL>select * from v$version;

Getting the Database Version Using Oracle PL/SQL

The following PL/SQL statements demostrates how to get the database version using DBMS_UTILITY.DB_VERSION.

SQL> list
  1  declare
  2     lv_version varchar2(100):='';
  3     lv_compat  varchar2(100):='';
  4  begin
  5     dbms_utility.db_version(lv_version,lv_compat);
  6     dbms_output.put_line('version = '||lv_version);
  7     dbms_output.put_line('compatability = '||lv_compat);
  8  exception
  9     when others then
 10             dbms_output.put_line(sqlerrm);
 11* end;
SQL> /
version = 9.2.0.1.0
compatability = 9.2.0.0.0

PL/SQL procedure successfully completed.
lingy
Posted: Saturday, July 10, 2010 3:08:50 PM

Rank: Administration
Groups: Administration , Member

Joined: 5/8/2009
Posts: 1,576
Points: 5,631

Oracle's dynamic performance views: V$SQL, V$SQLAREA, V$SQLSTATS and V$SQLTEXT

In Oracle, the dynamic performance views: V$SQL, V$SQLAREA, V$SQLSTATS and V$SQLTEXT can be used to collect statistics about the performance of their SQL statements. These dynamic performance views are updated constantly as the system is running. This makes it possible to watch the performance of a SQL statement while it is executing.

To use them, The SELECT_CATALOG_ROLE has to be granted to non-DBA users to enable users to SELECT from them.

V$SQLAREA

V$SQLAREA displays statistics on shared SQL areas and contains one row per SQL string. It provides statistics on SQL statements that are in memory, parsed, and ready for execution.

You should look at SQL statements that perform many physical reads by querying the V$SQLAREA view, examine these statements to see how they can be tuned to reduce the number of I/Os.

V$SQL

V$SQL lists statistics on shared SQL areas without the GROUP BY clause and contains one row for each child of the original SQL text entered.

Statistics displayed in V$SQL are normally updated at the end of query execution. However, for long running queries, they are updated every 5 seconds. This makes it easy to see the impact of long running SQL statements while they are still in progress.

V$SQLSTATS

V$SQLSTATS displays basic performance statistics for SQL cursors, with each row representing the data for a unique combination of SQL text and optimizer plan (that is, unique combination of SQL_ID, and PLAN_HASH_VALUE).

V$SQLSTATS contains a subset of columns that appear in V$SQL and V$SQLAREA and the column definitions are identical to those in the V$SQL and V$SQLAREA views. However, the V$SQLSTATS view differs from V$SQL and V$SQLAREA in that it is faster, more scalable, and has a greater data retention (the statistics may still appear in this view, even after the cursor has been aged out of the shared pool).

V$SQLTEXT

V$SQLTEXT displays the text of SQL statements belonging to shared SQL cursors in the SGA.

lingy
Posted: Saturday, July 10, 2010 3:10:57 PM

Rank: Administration
Groups: Administration , Member

Joined: 5/8/2009
Posts: 1,576
Points: 5,631

Renaming table in Oracle

Oracle provides a rename table syntax as follows:

alter table
   table_name
rename to
   new_table_name;

For example, the following SQL statement renames the organization table to new_organization:

alter table
   organization
rename to
   new_organization;
lingy
Posted: Saturday, July 10, 2010 3:14:33 PM

Rank: Administration
Groups: Administration , Member

Joined: 5/8/2009
Posts: 1,576
Points: 5,631

How to unlock Oracle user account?

Here's how to lock or unlock Oracle database user accounts.

 SQL> ALTER USER username ACCOUNT LOCK; 

 SQL> ALTER USER username ACCOUNT UNLOCK;
lingy
Posted: Saturday, July 10, 2010 3:16:57 PM

Rank: Administration
Groups: Administration , Member

Joined: 5/8/2009
Posts: 1,576
Points: 5,631

How to change a user's password in Oracle?

To change a user's password in Oracle, you need to execute the alter user command.

The syntax for changing a password is:

alter user user_name identified by new_password;

user_name is the user whose password you wish to change.

new_password is the new password to assign.
 

For example, if you wanted to reset the password for a user named smithj, and you wanted to set the new password to autumn, you would run the following command:

alter user dev identified by 128738;
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2010 Canaware Solutions. All rights reserved.
Powered by Canaware Forum version 2.4