Oracle Database Instance - Oracle 实例篇 2

来源:互联网 发布:淘宝手机充值代付 编辑:程序博客网 时间:2024/06/07 00:44

前言:接上一篇 Oracle Database Instance - Oracle 实例篇1 

Oracle Database Instance - Oracle 实例篇1  http://blog.csdn.net/nature_ann/article/details/9818671

1. Instance  Startup and Shutdown

1.1 Connection with Administrator Privileges

Database startup and shutdown arepowerful administrative options that are restricted to users who connect to Oracle Database withadministrator privileges.Normal users do not have control over the current status of an Oracle database.

Depending on the operating system, one of the following conditions establishesadministrator privileges for a user:

<< --- operating system privileges – SYSDBA/SYSOPER system privileges—password files --- >>

>>The operating system privileges of the user enable him or her to connect using administrator privileges.   

>>The user is granted theSYSDBA orSYSOPER system privileges and the database uses password files to authenticate database administrators over the network.

sysdba and sysoper  are specialsystem privilegesthat enable access to a database instance even when the database is not open.

Control of these privileges is outside of the database itself.

--两种情况:使用sysdba权限连接:使用sysoper权限连接。

When you connect with theSYSDBAsystem privilege, you are in the schema owned by SYS.

When you connect as SYSOPER, you are in the public schema.SYSOPER privileges are a subset of SYSDBA privileges.

1.2 How an Instance is started?

<< ---

第一读取参数文件(先找的是spfile,如果不存在就找拍pfile,也可以在数据库启动时具体指定用什么参数文件)。

第二读取参数文件里面的初始化配置参数。

第三根据初始化参数的设置分配SGA

第四启动后台进程。

第五打开警告日志和跟踪文件,跟踪里面的数据库的启动信息。

-- >>

>>Searches for aserver parameter file in a platform-specific default location and, if not found, for a text initialization parameter file(specifying STARTUP with theSPFILE or PFILE parameters overrides the default behavior)

>>Reads the parameter file to determine the values of initialization parameters

>>Allocates the SGAbased on the initialization parameter settings

>>Starts the Oracle background processes

>>Opens the alert log and trace files and writes all explicit parameter settings to the alert log in valid parameter syntax

1.3 How a database is mounted?

<< --- Talking about three points

The first:根据初始化参数文件里面配置的控制文件的变量,读取并打开它;数据库会去读控制文件里面数据文件和在线日志文件的信息。

The second:数据库mount状态下,只有管理员可以操作它,在数据库关闭的状态下,完成一些维护的工作,

The third CLUSTER_DATABASE参数的使用,设置它是否允许同一个数据库多实例同时mount

---- >>

The instance mounts a database to associate the database with this instance. To mount the database, the instance obtains the names of the database control files specified in thecontrol_files initialization parameter and opens the files. Oracle Database reads thecontrol files to find the names of the data filesand the online redo log filesthat it will attempt to access when opening the database.

In a mounted database , the database isclosed and accessible only todatabase administrators. Administrators can keep the database closed while completing specificmaintenance operations. However, the database isnot available for normal operations.

If Oracle Database allows multiple instances to mount the same database concurrently, then the CLUSTER_DATABASE initialization parameter setting can make the database available to multiple instances. Database behavior depends on the setting:

>>If  CLUSTER_DATABASEis  false (default) for the first instance that mounts a database, then only this instance can mount the database.

>>If  CLUSTER_DATABASE is  true  for the first instance, then other instances can mount the database if their CLUSTER_DATABASE parameter settings are set to true. The number of instances that can mount the database is subject to a predetermined maximum specified when creating the database.

1.4 How a database is opened?

<<-----打开mount状态下的数据库,使有效的用户可以正常访问和连接。通常情况下是数据库管理员可以打开数据库。Mount-open---->>

Opening a mounted database makes it available fornormal database operations. Any valid user canconnect to an open database andaccess its information. Usually, adatabase administrator opens the databaseto make it available for general use.

 

<<----打开数据库,会执行以下的事件:A表空间的在线数据文件会被打开,undo表空间除外。B选择一个undo表空(undo_tablespace参数是否被设置,有根据此选择,没有,第一个有效undo表空间将被选择)C打开在线重做日志文件--->>

When you open the database, Oracle Database performs the following actions:

>>Opens the online data files in tablespaces other than undo tablespaces

If a tablespace wasoffline when the database was previously shut down, then the tablespace and its corresponding data files will be offlinewhen the database reopens.

>>Acquires an undo tablespace

If multipleundo tablespaces exists, then theundo_tablespace initialization parameter designates the undo tablespace to use. If this parameter is not set, then thefirst available undo tablespace is chosen.

>>Opens the online redo log files

1.4.1 Read-Only Mode

<< --- 数据库可以在两种模式下打开:可读可写模式与只读模式,默认情况下是可读可写。可读可写模式可以更改数据,会产生redo,只读模式则相反--- >>

By default, the database opens inread/write mode. In this mode, users canmake changes to the data, generating redo in the online redo log. Alternatively, you can open inread-only mode topreventdata modification by user transactions.

<<---只读模式可以执行的操作:恢复或者是改变数据库状态的操作,而且没有redo产生。例如:改变数据文件的状态离线或者是在线(但是永久性表空间不可以离线)/离线的数据文件和表空间能被恢复/控制文件里面包含有效的数据库状态的信息||可以创建可读可写的临时表空间/有关操作系统的审计信息,跟踪文件以及警告日志可以被写入--->>

Read-only mode restricts database access to read-only transactions, whichcannot write to data files orto online redo log files. However, the database can perform recovery oroperations that change the database state withoutgenerating redo. For example, in read-only mode:

>>Data files can be takenoffline andonline. However, youcannot takepermanent tablespaces offline.

>>Offline data files andtablespacescan berecovered.

>>The control file remains available for updates about the state of the database.

>>Temporary tablespacescreated with the create temporary tablespace statement are read/write.

>>Writes to operating systemaudit trals,trace files, andalert logs can continue.

1.4.2 Database File Checks    

--数据文件/重做日志文件的检查

If any of the data files orredo log filesarenot present when the instance attempts to open the database, or if the filesare present but fail consistency tests, then the database returnsan error. Media recovery may be required. 

1.5 Shutdown Sequence

               图1 Instance and Database Shutdown Sequence

参考图 1

In a typical use case, you manually shut down the database, making it unavailable for users while you perform maintenance or other administrative tasks. You can use the SQL*Plusshutdown command or Enterprise Managerto perform these steps.你可以使用两种方法关闭数据库sql窗口命令shutdown或者是用企业管理器。

<<----三种状态的解释:1. Closed数据库是mount,在线数据文件和重做日志文件是关闭的,不能访问。2. Unmounted实例是开启的,但是不能访问控制文件。 3. Shutdown数据库关闭,不再是开启状态。----->>

Oracle Database automatically performs the following steps whenever an open database is shut downconsistently:

>>Database closed

The database is mounted, but online data files and redo log files are closed.

>>Database unmounted

The instance is started, but is no longer associated with the control file of the database.

>>Database instance shut down

The database instance is no longer started.

---不经过以上的步骤,如果实例是失效的或者是shutdown abort,实例立即终止

Oracle Database does not go through all of the preceding steps in an instance failure or shutdown abort, which immediately terminates the instance.

1.6 Shutdown Modes

<<--------一共有四种模式 abort/immediate/transactional/normal------->>

Table 1 summarizes the behavior of the different shutdown modes.

Database Behavior

Abort

Immediate

Transactional

Normal

Permits new

user connections

No

No

No

No

Waits until current

sessions end

No

No

No

Yes

Waits until current

transactions end

No

No

Yes

Yes

Performs a

Checkpoint and

closes open files

No

Yes

Yes

Yes

<<--------

shutdown abort: 这种方式速度是最快的,但是要在紧急情况下使用,当你重新打开数据库时时间会很长,因为它要执行实例的恢复工作。

shutdown immediatea:这种方式的速度较abort次之。终止执行的sql语句,断开用户连接,终止活动的事务,回滚未提交的事务。

shutdown transactional:阻止一个新的事务,等待所有当前的事务完成。这种模式花费的时间取决于当前事务完成的情况。

shutdown normal: 这种方式是默认的方式,它等待所有的连接用户断开连接。

------>>

>>shutdown abort

This mode is intended for emergency situations, such as when no other form of shutdown is successful. This mode of shutdown is thefastest. However, a subsequent open of this database may take substantiallylonger because instance recovery must be performed to make the data files consistent.

Because shutdown abort does notcheckpoint the open data files, instance recovery is necessary before the database can reopen. The other shutdown modes do not require instance recovery before the database can reopen.

>>shutdown immediate

This mode is typically the fastest next to shutdown abort. Oracle Databaseterminates any executing SQL statements and disconnects users. Active transactions are terminated and uncommitted changes are rolled back.

>>shutdown transactional

This mode prevents users fromstarting new transactions, butwaits for all current transactions to complete before shutting down. This mode can take a significant amount of time depending on the nature of the current transactions.

>>shutdown normal

This is the default mode of shutdown. The database waits forall connected users to disconnectbefore shutting down.

1.7 How a database is closed?

The database close operation is implicit in a database shutdown. The nature of the operation depends on whether the database shutdown is normal or abnormal.  

--这个关闭操作暗示着数据库要执行shutdown命令。这个操作有两种情况:正常关闭还是非正常关闭。

1.7.1 How a database Is closed during normal shutdown

<<-------数据库正常关闭的情况下:SGA里面的数据写到数据文件和在线重做日志文件;数据库关闭数据文件和在线重做日志文件;所有的离线表空间的数据文件已经被关闭,数据库重新被打开,离线的表空间依旧保持离线的状态。至此,数据库已经正常关闭,无法进行正常的访问,但是控制文件保持打开的状态------->>

When a database is closed as part of ashutdown with any option other thanabort , Oracle Databasewrites data in the SGA to the data files and online redo log files. Next, the database closes online data files and online redo log files. Any offline data files of offline tablespaces have been closed already. When the database reopens,any tablespace that was offline remains offline.

At this stage, the database is closed and inaccessible for normal operations. The control files remain open after a database is closed.

1.7.2 How a database Is closed during abnormal shutdown

<< ---数据库执行shutdown abort命令或者是异常终止。数据库不写buffers中的数据到数据文件和日志文件。重新打开数据库需要执行实例恢复--- >>

If a shutdown abortorabnormal termination occurs, then the instance of an open database closes and shuts down the database instantaneously. Oracle Database does not write data in the buffers of the SGA to the data files and redo log files. The subsequent reopening of the database requiresinstance recovery, which Oracle Database performs automatically.

1.8 How a database is Unmounted?

After the database is closed, Oracle Database unmounts the database to disassociate it from the instance. After a database is unmounted, Oracle Database closes the control files of the database. At this point, the instance remains in memory.

---数据库是unmounts状态,控制文件将关闭,这时候,该实例保留在内存之中。

1.9 How an instance is shut down?

<<--------关闭数据库的最后一步是关闭实例,实例关闭,SGA被请出内存,后台进程也被终止。 ------->>

The final step in database shutdown isshutting down the instance. When the database instance is shut down, the SGA is removed from memory and the background processes are terminated.

<<--------在异常的情况下,实例的关闭不是干净的。SGA没有被移出内存,后台进程也没有被终止,以前的这个实例继续存在,随后的打开数据库将会失败。在这种情况下,一可以强制打开一个实例或者是在sqlplus窗口/企业管理器发出一个shutdown abort 命令。 ------->>

In unusual circumstances, shutdown of an instance maynot occurcleanly. Memory structures may not be removed from memory or one of the background processes may not be terminated. When remnants of a previous instance exist, a subsequent instance startup may fail. In such situations, you can force the new instance to start by removing the remnants of the previous instance and then starting a new instance, or by issuing ashutdown abort statement in SQL*Plus or using Enterprise Manager.

 

待续。。。。

 

原创粉丝点击