Oracle Database Instance

数据库与实例的区别:

A database instance is a set of memory structures that manage database files.

A database is a set of physical files on disk created by the CREATE DATABASE statement. The instance manages its associated data and serves the users of the database.

Because an instance exists in memory and a database exists on disk, an instance can exist without a database and a database can exist without an instance.

When an instance is started, Oracle Database allocates a memory area called the system global area (SGA) and starts one or more background processes.

Startup/shutdown是对实例操作而不是数据库。在RAC中实例各自startup/mount/open

A database instance begins when it is created with the STARTUP command and ends when it is terminated. During this period, a database instance can associate itself with one and only one database.

12.2 RAC可以设置read only实例

Every database instance is either read/write or read-only.

In previous releases, all database instances—unless they accessed a standby database—were read/write. Starting in Oracle Database 12c Release 2 (12.2), read-only and read/write instances can co-exist within a single database. This configuration is useful for parallel SQL statements that both query and modify data, because both read/write and read-only instances can query, while the read/write instances modify.

Unlike read/write instances, read-only instances have the following characteristics:

  1. Can only open a database that has already been opened by a read/write instance
  2. Disable many background processes, including the checkpoint and archiver processes, which are not necessary
  3. Can mount a disabled redo thread or a thread without any online redo log
  4. Data files can be taken offline and online. However, you cannot take permanent tablespaces offline.
  5. Offline data files and tablespaces can be recovered.
  6. The control file remains available for updates about the state of the database.
  7. Temporary tablespaces created with the CREATE TEMPORARY TABLESPACE statement are read/write.
  8. Writes to operating system audit trails, trace files, and alert logs can continue.

To designate an instance as read-only, set the INSTANCE_MODE initialization parameter to READ_ONLY. The default value of the parameter is READ_WRITE.

Database Instance Startup and Shutdown

  1. How an Instance Is Started

The stages are as follows:

  1. Searches for a server parameter file in a platform-specific default location and, if not found, for a text initialization parameter file (specifying STARTUP with the SPFILE or PFILE parameters overrides the default behavior)
  2. Reads the parameter file to determine the values of initialization parameters
  3. Allocates the SGA based on the initialization parameter settings
  4. Starts the Oracle background processes
  5. Opens the alert log and trace files and writes all explicit parameter settings to the alert log in valid parameter syntax

  1. How a Database Is Mounted

To mount the database, the instance obtains the names of the database control files specified in the CONTROL_FILES initialization parameter and opens the files. Oracle Database reads the control files to find the names of the data files and the online redo log files that it will attempt to access when opening the database.

  1. How a Database Is Opened

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

  1. Opens the online data files in tablespaces other than undo tablespaces
  2. Acquires an undo tablespace
  3. Opens the online redo log files

Database and Instance Shutdown

  1. Shutdown Modes

Note: In a CDB, issuing SHUTDOWN ABORT on a PDB is equivalent to issuing SHUTDOWN IMMEDIATE on a non-CDB.

  1. How a Database Is Closed

How a Database Is Closed During Normal Shutdown

When a database is closed as part of a SHUTDOWN with any option other than ABORT, Oracle Database writes data in the SGA to the data files and online redo log files.

Afterward, 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.

How a Database Is Closed During Abnormal Shutdown

In an abnormal shutdown, 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 requires instance recovery, which Oracle Database performs automatically.

  1. How a Database Is Unmounted

After a database is unmounted, Oracle Database closes the control files of the database. At this point, the database instance remains in memory.

  1. How an Instance Is Shut Down

When the database instance shuts down, the SGA ceases to occupy memory, and the background processes terminate.

有时oracle不能shutdown clearly会残存内存或进程未移除,这时在下次启动数据库时会失败,你可以在启动前执行shutdown abort或手动清理下

In unusual circumstances, shutdown of a database instance may not occur cleanly. 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 a SHUTDOWN ABORT statement.

另外有时清理进程自身可能遇到问题,导致PMON或实例中止

In some cases, process cleanup itself can encounter errors, which can result in the termination of process monitor (PMON) or the instance.

 The dynamic initialization parameter INSTANCE_ABORT_DELAY_TIME specifies how many seconds to delay an internally generated instance failure. This delay gives you a chance to respond. The database writes a message to the alert log when the delayed termination is initiated.

  • Instance Recovery

Oracle是根据 redo threads的状态来决定是否需要进行instance recovery

A redo thread is a record of all of the changes generated by an instance. A single-instance database has one thread of redo, whereas an Oracle RAC database has multiple redo threads, one for each database instance.

Whether instance recovery is required depends on the state of the redo threads.

A redo thread is marked open in the control file when a database instance opens in read/write mode, and is marked closed when the instance is shut down consistently. If redo threads are marked open in the control file, but no live instances hold the thread enqueues corresponding to these threads, then the database requires instance recovery.

Oracle Database performs instance recovery automatically in the following situations:

  1. The database opens for the first time after the failure of a single-instance database or all instances of an Oracle RAC database. This form of instance recovery is also called crash recovery. Oracle Database recovers the online redo threads of the terminated instances together.
  2. Some but not all instances of an Oracle RAC database fail. Instance recovery is performed automatically by a surviving instance in the configuration.

The SMON background process performs instance recovery, applying online redo automatically. No user intervention is required.

实例恢复过程:

  1. reapplies all changes recorded in online redo log to rolling forward

这里是从最近一次checkpoint开始应用日志

Oracle Database uses the checkpoint position, which guarantees that every committed change with an SCN lower than the checkpoint SCN is saved on disk.

undo的更改也会记录到redo, 所以会同时恢复undo表空间

  1. 通过检查redo log记录中未提交的事务,找出其指向的undo blocks来进行回滚


Oracle Database can roll back multiple transactions simultaneously as needed. All transactions that were active at the time of failure are marked as terminated. Instead of waiting for the SMON process to roll back terminated transactions, new transactions can roll back individual blocks themselves to obtain the required data.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值