search
HomeDatabaseMysql Tutorial在SQL*Plus中启动和关闭Oracle数据库

关闭数据库 与数据库启动一样,有几个可供选择的选项用于关闭数据库。无论在什么情况下,读者都需要弄清楚这些关闭选项

关闭数据库

        与数据库启动一样,有几个可供选择的选项用于关闭数据库。无论在什么情况下,读者都需要弄清楚这些关闭选项

关闭数据库的语法是:SHUTDOWN [ NORMAL | TRANSACTIONAL | IMMEDIATE | ABORT ]

注意:如果不在windows服务中事先关闭OracleDBControlSID,则使用shutdown或shutdown normal 来关闭数据库时没有相应结果,但其他几个选项有响应结果。

一、 NORMAL(正常)选项

        shutdown 和 shutdown normal 作用相同,使用带有normal选项的shutdown语句将以正常方式关闭数据库。用normal选项时,Oracle将执行如下操作:

        1、 阻止任何用户建立新的连接

        2、 等待当前所有正在建立连接的用户主动断开连接。正在连接的用户能够继续他们当前的工作,甚至能够提交新的事务。

        3、 一旦所有的用户都断开连接,才能进行关闭、卸载数据库,并终止例程。

注意:按这个选项关闭数据库,则在下次启动数据库时不需要进行任何恢复操作。

二、 TRANSACTIONAL(事务处理)选项

        transactional选项比normal选项稍微主动些,,他能在尽可能短的时间内关闭数据库。按transactional选项关闭数据库时,Oracle将等待所有未提交的事务完成后再关闭数据库。用transactional选项关闭数据库时,oracle将执行如下操作:

        1、 阻止任何用户建立新的连接,同时阻止当前连接的用户开始任何新的事务。

        2、 等待所有当前未提交的活动事务提交完毕,然后立即断开用户的连接。

        3、 一旦所有的用户都断开连接,才进行关闭、卸载数据库,并终止例程 。

注意:按这个选项关闭数据库,则在下次启动数据库时不需要进行任何恢复操作。

三、 IMMEDIATE(立即)选项

        通常在以下几种情况下需要使用该选项来关闭数据库

        1、 即将启动自动数据库备份操作

        2、 即将发生电力供应中断

        3、 数据库本身或者某个数据库应用程序发生异常,并且这时候无法通知用户主动断开连接,或者数据库用户本身无法制定断开操作

        使用IMMEDIATE选项关闭数据库时,Oracle将执行如下操作:

        1、 阻止任何用户建立新的连接,同时阻止当前连接的用户开始任何新的事务。

        2、 任何当前未提交的事务均被退回

        3、 Oracle不再等待用户主动断开连接,而是直接关闭、卸载数据库,并终止例程。

注意:按这个选项关闭数据库,则在下次启动数据库时不需要进行任何恢复操作。

四、 ABORT(终止)选项

        通常在以下情况下可以考虑使用abort选项来关闭数据库

        1、 数据库本身或者某个数据库应用程序发生异常,并且使用其他选项均无效

        2、 出现紧急情况,需要立刻关闭数据库

        3、 在启动数据库例程时产生错误

        用abort选项来关闭数据库时,Oracle将执行如下操作:

        1、 阻止任何用户建立新的连接,同时阻止当前连接的用户开始任何新的事务。

        2、 立即结束当前正在执行的SQL语句

        3、 任何未提交的事务均不被回退

        4、 立即断开所有的用户的连接,关闭、卸载数据库,并终止例程

注意:按这个选项来关闭数据库,由于当前未完成的事务并不会回退,所以可能会丢失一部分数据信息,并对数据库的完整性造成损坏,需要在下一次启动数据库的时候进行恢复。


启动数据库

        数据库有三种启动模式,分别代表启动数据库的三个步骤。当数据库管理员使用startup命令时,可以指定不同的选项来决定将数据库的启动推进到哪个启动模式。在进入某个模式后,可以使用alter database命令来将数据库提升到更高的启动模式,但是不能使数据库降低到前面的启动模式。

启动模式

说明

对应的界面提示信息

NOMOUNT

启动例程,但不装载数据库,即只完成启动步骤的第一步

Oracle例程已经启动

MOUNT

启动例程,装载数据库,但不打开数据库,即只完成启动步骤的第一步和第二步

Oracle例程已经启动

数据库装载完毕

OPEN

启动例程,装载数据库,打开数据库,即完成全部的三个步骤

Oracle例程已经启动

数据库装载完毕

数据库已经打开

启动数据库的语法是:STARTUP [ NOMOUNT | MOUNT | OPEN | FORSE ] [ RESTRICT ] [ PFILE = 'PFILE_NAME' ];

一、 NOMOUNT选项

        该选项只创建例程,但不装在数据库。Oracle读取参数文件,仅为例程创建各种内存结构和后台服务进程,用户能够与数据库进行通信,但不能使用数据库中的任何文件。

        如果要执行下列维护工作,就必须使用该选项来启动数据库:

        1、 运行一个创建新数据库的脚本

        2、 重建控制文件

注意:在该启动模式下,只能访问到那些与SGA区相关的数据字典视图,这些视图的信息都是从SGA区获取的,与数据库是否装载,是否打开无关。

二、 MOUNT选项

        该选项不仅创建历程,还装载数据库,但却不打开数据库。Oracle读取控制文件,并从中获取数据库名称、数据文件的位置、名称等数据库物理结构的信息,为下一步打开数据库做好准备。

        在这种模式下,仅数据库管理员可以通过部分命令修改数据库,用户还无法与数据库建立连接或会话。这在进行一些特定的数据库维护工作时是十分必要的。

        如果要执行下列维护工作,就必须使用该选项启动数据库:

        1、 重新命名、增加、删除数据文件和重做日志文件

        2、 执行数据库的完全恢复

        3、 改变数据库的归档模式

注意:在该模式下,除了可以访问那些与SGA区相关的数据字典视图以外,还可以访问到那些与控制文件相关的数据字典视图,这些视图信息都是从控制文件中获取的。 

三、 OPEN选项

        该选项不仅创建例程,还装载数据库,并且打开数据库。这是正常的启动模式。如果startup语句没有指定任何选项,那就是使用该选项进行德启动。

        将数据库设置为打开状态后,任何具有create session权限的用户都能连接到数据库,并且进行常规的数据访问操作。

四、 FORSE选项

        如果在正常方式启动数据库时遇到了困难,则可以使用FORSE选项启动。FORSE选项与正常启动选项之间的差别在于无论数据库处于什么模式,都可以使用该选项,即FORSE选项首先关闭异常数据库,然后在重新启动他,而不需要事先用shutdown语句关闭数据库。 

五、 RESTRICT选项

        用该选项启动数据库时,会将数据库启动到open模式,但此时只有拥有restricted session   权限的用户才能访问数据库。如果需要在数据库处于open模式下执行维护任务,又要保证此时其他用户不能再数据库上建立连接和执行任务,则需要使用restrict 选项来打开数据库,以便完成以下任务:

        1、 执行数据库数据的导入或导出操作

        2、 执行数据库装载操作(用SQL*Loader)

        3、 暂时阻止一般的用户使用数据

        4、 进行数据库移植或升级

        当工作进行完毕后,可以使用 alter system disable restrict session 语句来禁用restricted session,以便一般用户能连接并使用数据库。

六、 PFILE选项

        数据库例程在启动的时候必须读取一个初始化参数文件,oracle必须从初始化参数文件中获得有关例程的参数配置信息。如果在执行startup语句时没有指定pfile 选项,oracle将首先读取默认位置的服务器初始化参数文件(spfile),如果没有找到默认的服务器初始化参数文件,oracle将继续读取默认的文本初始化参数文件(pfile),如果也没有到文本初始化参数文件,启动就会失败。

        使用startup语句时可以通过pfile选项指定一个文本初始化参数文件。

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software