Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Oracle Concepts: The Instance and the Database

The complexity of information storage and retrieval is hidden from casual database users, but that's exactly what you need to know if you want to administer Oracle.


advertisement
atabase programs, with few exceptions, need to utilize both the computer's memory and permanent storage space such as the hard drive to operate. The drives provide both long-term storage and the necessary room for millions of records and gigabytes worth of information. However, accessing information from disks is much slower than retrieving the same information from memory. Therefore, database engines use memory to cache information, which speeds its retrieval.

The complexity of how the information is stored and where it is retrieved from is hidden from the casual user who queries the database. But if you plan on administering Oracle, you need to become familiar with how Oracle handles both resources. In this article, I discuss two basic but important concepts with regard to memory and disk: the database and the instance.

The Database
In Oracle, a database is used to describe the physical files used to store information. There are three types of physical files:

  • Data files store—you guessed it—all the data that caused us to get a database engine to begin with.

  • Control files store metadata about the rest of the database for use by the Oracle engine.

  • Redo-log files are used to record all changes made to the data for use in backup and recovery.
Regardless of how many files are used, they are all part of one database.



SQL Server uses the term database very differently. It's used to define a collection of objects such as tables. Each of these collections is stored in a separate set of files. One SQL Server installation typically contains many databases. In fact, the SQL Server installation process itself creates four databases.

Understanding how each vendor uses the term is critical to understanding the literature written about each of the products.

The Instance
Database files themselves are useless without the memory structures and processes to interact with the database. Oracle defines the term instance as the memory structure and the background processes used to access data from a database.

An instance has two major memory structures:

  • The System Global Area, also known as the Shared Global Area (SGA) stores information in memory that is shared by the various processes in Oracle.

  • The Program Global Area, also known as the Private Global Area (PGA) contains information that is private to a particular process.
The SGA contains, among other things, the database buffer cache that is used to cache information read from the data files, a data dictionary cache used to cache metadata information, and a library cache that caches recently used SQL and PL/SQL statements. The PGA is used to allocate memory for information such as sort space, variables, arrays, and cursor information that is private to each process. The instance also contains numerous background processes that cooperate to fulfill all the various functions needed. Some examples of these processes include the Database Writer, responsible for writing all changes to the database, and the Process Monitor, responsible for cleaning up after failed user processes.

In the SQL Server world, it has not been till the 2000 version that the word instance has had any practical significance. Up to that point, you could only have one installation of SQL Server on a machine. With the 2000 version, you can actually have many "instances" of SQL Server running at once. In the SQL Server world, an instance refers to both the memory and files used by that particular installation.

More Than Just a Name
Other than providing yet more acronyms to remember, is there any practical implication to the distinction between the disk files and memory in Oracle? The answer is a resounding yes. Let's look at a couple of Oracle features that illustrate this.

  Oracle Parallel Server  A single machine can contain only so many CPUs and so much memory. The separation between the memory structures and data files allows Oracle to scale beyond a single machine by allowing multiple instances—that is, multiple separate Oracle memory structures—on different machines to access the same database.

My understanding is that the configuration and use of Parallel Server is rather complicated. Additionally, single Oracle boxes (especially on Unix) can scale quite high with numerous CPUs and large amounts of memory. You may never need this feature, but it does illustrate one practical outcome of the division between the database and the instance.

  Starting Oracle Server  The division between the instance and the database can be seen by the various steps for starting Oracle. The first step is when the instance itself is started. Memory in the computer is allocated and the various background processes are started. The second step is when the instance then "mounts" the database—i.e., accesses the database files themselves. The last step is opening the database for access by users.

Although you normally make Oracle go through all three steps when starting, it is possible and sometimes necessary to make Oracle stop at a particular stage in the process. Let's look at some of the syntax involved. Use SQL*Plus to log in to Oracle and try these commands if you like. (Assuming Oracle has already started, you can issue the shutdown command to first shut Oracle down.)

STARTUP or STARTUP OPEN tells Oracle to go through all three stages of the startup process. If you want Oracle only to start up the instance, you can instead issue a STARTUP NOMOUNT instead. Oracle will start the instance but not touch any of the database files yet.

Why would you want to do this? Well, let's say you were creating new control files (the files used to store the metadata about the rest of the database) or a whole new database. Such operations need to occur before the database is accessed. You can also issue a STARTUP MOUNT (or if you've previously issued a STARTUP NOMOUNT you can issue an ALTER DATABASE MOUNT) to tell Oracle to mount the database files. In this condition, the instance itself has access to all the information regarding the database. However, it is not yet accessible to users. One example of an operation that must be done in this state is renaming the files used by the SYSTEM tablespace. Once you've finished your changes you can issue the ALTER DATABASE OPEN command to make the database accessible to the public.

As I said, in Oracle an instance refers to the memory and background processes. A database refers to the physical files that store the data. Both are needed to provide the user with the information he or she needs. But Oracle allows (and in some cases requires) you to deal with both parts separately.



   
Joseph Lax is the principal of DB Directions, a company specializing in all aspects of database architecture. He has spent the last 12 years providing expertise on performance optimization, test design, and backup and recovery strategies for banks, telecommunication firms, and manufacturing companies.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap