当前位置:Gxlcms > 数据库问题 > Oracle表空间基础(4)

Oracle表空间基础(4)

时间:2021-07-01 10:21:17 帮助过:7人阅读

作用描述 normal 表空间正常离线,在所有表空间的所有数据文件上执行检查点操作,当表空间online,不需要进行介质恢复 temporary 对表空间在线的数据文件进行检查点操作,离线数据文件不进行检查点,当表空间online,执行检查点的数据文件不需要进行介质恢复 immediate 在所有数据文件上不执行检查点,表空间online,需要执行检查点,无法在noarchivelog上使用immediate方式offline表空间

 以下内容为测试结果:

SQL> alter tablespace test_tbs01 offline normal;
Tablespace altered.

SQL> alter tablespace test_tbs01 online;
Tablespace altered.

SQL> alter tablespace test_tbs01 offline temporary;
Tablespace altered.

SQL> alter tablespace test_tbs01 online;
Tablespace altered.

SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Current log sequence           2

SQL> alter tablespace test_tbs01 offline immediate;
alter tablespace test_tbs01 offline immediate
*
ERROR at line 1:
ORA-01145: offline immediate disallowed unless media recovery enabled

 

四、只读表空间

所有的表空间在创建时默认都是可读写的(read write),同时使用read only选项可以讲表空间置为只读状态。只读表空间可以阻止对表空间内数据文件的写操作,其主要目的是为了避免对大型数据库的静态部分执行备份和恢复操作。另外,只读表空间提供了一种历史数据的保存方法,在只读表空间内,任何对象都无法修改,而不论用户是否有更新的权限。粗体部分的阐述和实验结果冲突

有关只读表空间的操作限制:

# 只读表空间不允许创建对象。
SQL> create table t3 (rec_id number,name varchar(4)) tablespace ro_tbs;
create table t3 (rec_id number,name varchar(4)) tablespace ro_tbs
*
ERROR at line 1:
ORA-01647: tablespace ‘RO_TBS‘ is read only, cannot allocate space in it

# 只读表空间不允许修改记录。
SQL> update t2 set name=‘Blank‘ where id=2002;
update t2 set name=‘Blank‘ where id=2002
       *
ERROR at line 1:
ORA-00372: file 7 cannot be modified at this time
ORA-01110: data file 7: ‘/u01/app/oracle/oradata/stdb/read_only.dbf‘

# 只读表空间不允许删除记录。
SQL> delete from t2 where id=2002;
delete from t2 where id=2002
            *
ERROR at line 1:
ORA-00372: file 7 cannot be modified at this time
ORA-01110: data file 7: ‘/u01/app/oracle/oradata/stdb/read_only.dbf‘

# 只读表空间允许删除表。
SQL> drop table t2;
Table dropped.

# 只读表空间允许修改对象。
SQL> alter table t3 modify (name varchar(10));
Table altered.

在将表空间置为只读之前应考虑如下的前提条件:

1、表空间必须在线,而且必须确保没有要应用到表空间上的撤销信息。(表空间上的事务都应被提交)

SQL> alter tablespace test_tbs01 offline normal;
Tablespace altered.

SQL> alter tablespace test_tbs01 read only;
alter tablespace test_tbs01 read only
*
ERROR at line 1:
ORA-01539: tablespace ‘TEST_TBS01‘ is not online

2、不能将活动事务的撤销表空间和系统表空间置为只读。

3、如果当前表空间正在联机备份,不能将该表空间置为只读状态,因为在备份结束后会更新表空间上所有数据文件的文件头信息。 

当执行alter tablespace ... read only语句之前,在该表空间上有一事务挂起或未被提交,该语句将等待表空间上的事务提交或回滚后才会返回;如果在执行alter tablespace ... read only语句之前,表空间上的事务挂起或未被提交,但某一时刻该事务回滚到了一个保存点(savepoint),则此时将执行事务的回滚,alter tablespace ... read only语句不再等待该事务。如果发现alter tablespace ... read only语句长时间无法返回,则需要判断是否有事务阻止了该语句的完成,并通知事务的所有者,必要时,中断这些事务。

SQL> select sql_text,saddr from v$sqlarea,v$session
  2  where v$sqlarea.address=v$session.sql_address
  3  and sql_text like ‘alter tablespace%‘;
SQL_TEXT                                           SADDR
-------------------------------------------------- ----------------
alter tablespace test_tbs01 read only              0000000070F6FE40 -->  //这是将表空间置为只读语句的会话地址

SQL> select ses_addr,start_scnb from v$transaction order by start_scnb;
SES_ADDR         START_SCNB
---------------- ----------
0000000070F829F0     643505   -->  //这是将表空间置为只读状态之前的操作
0000000070F6FE40     643536   -->  //这是将表空间置为只读的语句

SQL> select t.ses_addr,s.username,s.machine from v$session s,v$transaction t
  2  where t.ses_addr=s.saddr
  3  order by t.ses_addr;
SES_ADDR         USERNAME                       MACHINE
---------------- ------------------------------ --------------------
0000000070F6FE40 SYS                            stdb.localdomain
0000000070F829F0 SYS                            stdb.localdomain   --> //需要中断这个操作表空间才能被置为只读 

Oracle表空间基础(4)

标签:

人气教程排行