Oracle表空间的状态
只要数据库处于OPEN状态,除了SYSTEM表空间外的其他表空间,都可以将其置为online或offline状态。SYSTEM表空间之所以不能置为of
前几天问一个表空间状态的问题,也暴露了自己基础知识的薄弱,之所以总结如下两篇博文,主要还是让自己静下心来,补一下相关知识点,并通过实践强化自己的理解。
主要参考:
《11g Concept》
《11g Administrator's Guide》
Oracle 11g表空间dbf文件迁移
移动Oracle表空间数据文件方案
删除临时表空间ORA-25152错误
Oracle表空间增长异常解决又一例
Oracle表空间Offline的三种参数详述
Oracle 11g下加密表空间的使用
表空间的ONLINE和OFFLINE状态
1. 只要数据库处于OPEN状态,除了SYSTEM表空间外的其他表空间,都可以将其置为online或offline状态。SYSTEM表空间之所以不能置为offline,是因为其中保存的数据字典需要一直使用。将表空间置为offline,可能的原因包括维护、备份以及恢复等目的。
3. 如果表空间处于offline状态,那么Oracle不会允许任何对该表空间中对象的SQL执行。表空间置为offline时仍处于活动状态的语句在交易级别并不会受影响。Oracle会保存这些尚未完成语句相关的回滚数据到SYSTEM表空间。当表空间置为online时,如果有必要,那么Oracle会应用这些回滚数据。
3. 除了Oracle外,没有任何应用能够读取或编辑offline的表空间。因此,offline的表空间更不能导到其他数据库。
4. Oracle在一些场景下会自动切换表空间状态从online到offline。例如,当数据库写进程DBWn,尝试几次仍不能写入表空间的数据文件中。用户访问offline表空间时会收到一个报错。如果造成这种磁盘IO失败的问题是介质错误,解决这问题之后需要恢复表空间。
5. 将表空间置为offline可能包含如下原因:
(1) 需要禁止访问一部分数据库的场景。
(2) 执行一次offline表空间备份(尽管表空间可以在online和使用情况下备份)。
(3) 当更新或维护应用时,需要让应用和对应的表临时不能访问。
(4) 重命名或重分配表空间中的数据文件。
当表空间置为offline,数据库会将关联的所有数据文件都置为offline状态。但是如下表空间不能置为offline:
> SYSTEM
> UNDO表空间
> 临时表空间
6. 将表空间置为offline之前,若有用户设置该表空间为其默认表空间,需要考虑是否需要改变其默认表空间。之所以这样做,是因为这些用户将不能访问offline表空间中的对象。
7. 使用ALTER TABLESPACE ... OFFLINE语句可以添加如下参数:
NORMAL:如果表空间的任何数据文件没有出现错误,表空间能够正常地置为offline。如果出现写错误,那么表空间中的数据文件不会被置为offline。当明确使用OFFLINE NORMAL,数据库会对所有数据文件进行一次checkpoint检查点事件,NORMAL是默认设置。
TEMPORARY:表空间能够临时置为offline状态,即使一个或多个文件出现错误。当使用OFFLINE TEMPORARY,数据库会将还没有置为offline的数据文件进行置位操作,并执行检查点事件。
如果没有文件是offline,但使用了temporary语句,那么当将表空间置为online时不需要介质恢复。然而,如果表空间的一个或多个文件由于写入错误因此导致offline状态,能够临时将表空间置为offline状态,恢复online之前需要对表空间进行恢复操作。
IMMEDIATE:表空间能够立即设置为offline状态,数据库不会进行任何数据文件的检查点事件。当使用OFFLINE IMMEDIATE,那表空间置为online之前需要对表空间进行介质恢复操作。但是如果数据库处于NOARCHIVELOG模式,表空间就不能立即置为offline状态。
8. 如果必须设置表空间为offline状态,建议首先使用默认的NORMAL语句。他会确保当表空间置为online前不需要执行恢复操作,尽管在不完全恢复之后,,使用LATER DATABASE OPEN RESTLOGS语句重置了redo日志sequence。
仅仅当不能使用NORMAL方式将表空间置为offline时,可以使用TEMPORARY。使用TEMPORARY后,在表空间置为online前,仅需要恢复那些出错的offline文件。
如果NORMAL和TEMPORARY都失败时,才可以选择使用IMMEDIATE选项。
9. 如果表空间没有“干净地”置为offline(也就是没有使用NORMAL语句执行的offline操作),那么置为online前需要首先对该表空间执行介质恢复操作。否则数据库会报错,表空间仍处于offline状态。
实验:
1. 设置表空间DCSOPEN_TBS为offline:
SQL> alter tablespace dcsopen_tbs offline;
Tablespace altered.
2. 查询数据文件状态:
select file#, name, status from v$datafile;
file #name
status
--- ------------------------------------------------------ ----------
11 /oracle/oradata_petest/petest/dcsopen_tbs02.dbf OFFLINE
DCSOPEN_TBS使用的数据文件状态已经置为OFFLINE。
3. 尝试查询已OFFLINE表空间:
SQL> select * from test;
select * from test
*
ERROR at line 1:
ORA-00376: file 7 cannot be read at this time
ORA-01110: data file 7: '/oracle/oradata_petest/petest/dcsopen_tbs01.dbf'
报错,提示此时数据文件不能读。
4. 将表空间置为online:
SQL> alter tablespace dcsopen_tbs online;
Tablespace altered.
file #name
status
--- ------------------------------------------------------ ----------
11 /oracle/oradata_petest/petest/dcsopen_tbs02.dbf ONLINE
更多详情见请继续阅读下一页的精彩内容:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
