Oracle中的实例和数据库概念

来源:互联网 发布:淘宝充值流量怎么查询 编辑:程序博客网 时间:2024/05/18 01:57

在Oracle中,数据库用来描述存储信息的物理文件,包括数据文件、控制文件以及重做日志(Redo-log)。

实例是内存结构和与数据库交互的多个进程。


Oracle Server启动经过3个步骤:

第一步,内存结构被建立、相关进程启动;

第二步,挂载数据库;

第三步,开放数据库为用户提供访问。

如果只启动实例不访问数据库可以使用“STARTUP NOMOUNT”参数。


原文:http://webcache.googleusercontent.com/search?q=cache:07l5aoU1M6UJ:www.devx.com/dbzone/Article/20713+instance+definition+database&cd=3&hl=zh-CN&ct=clnk

Database 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 thedatabase. 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: thedatabase and theinstance.

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 adatabase 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 thedatabase. Oracle defines the terminstance as the memory structure and the background processes used to access data from adatabase.

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. Theinstance also contains numerous background processes that cooperate to fulfill all the various functions needed. Some examples of these processes include theDatabase Writer, responsible for writing all changes to thedatabase, 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, aninstance 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 samedatabase.

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 theinstance itself is started. Memory in the computer is allocated and the various background processes are started. The second step is when theinstance then "mounts" thedatabase—i.e., accesses thedatabase files themselves. The last step is opening thedatabase 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 theinstance, you can instead issue a STARTUP NOMOUNT instead. Oracle will start theinstance but not touch any of thedatabase 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 thedatabase) or a whole newdatabase. Such operations need to occur before thedatabase is accessed. You can also issue a STARTUP MOUNT (or if you've previously issued a STARTUP NOMOUNT you can issue an ALTERDATABASE MOUNT) to tell Oracle to mount thedatabase files. In this condition, theinstance itself has access to all the information regarding thedatabase. 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 ALTERDATABASE OPEN command to make thedatabase accessible to the public.

As I said, in Oracle an instance refers to the memory and background processes. Adatabase 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. 


原创粉丝点击