今天又碰到一个奇怪的问题了。 有一个表空间:CHEN ,原先是read only。 在容量报警之后,想要添加数据文件,发生错误。说这个表空间是offline的状态,无法添加数据文件。
随后alter tablespace CHEN online. 显示:Tablespace altered.  但是经查,这个状态还是read only。 当然也无法添加新的数据文件。
之后,switch到一个新的数据文件:alter tablespace CHEN rename datafile ‘/u04/app/oracle/kenneth/kenneth/chen01.dbf'
to '/u04/app/oracle/kenneth/kenneth/chen02.dbf';

这个倒是成功了。但是无法添加数据文件的问题依旧存在。


再次回到原点,查询表空间的几种状态:

offline/online/read only/read write;

这个思路是由于在尝试更改表空间中数据文件的大小时,出现的错误:

alter database datafile '/u04/app/oracle/kenneth/kenneth/chen02.dbf' resize 100M

Error report:

SQL Error: ORA-02495: cannot resize file /u04/app/oracle/kenneth/kenneth/chen02.dbf, tablespace CHEN is read only

02495. 00000 -  "cannot resize file %s, tablespace %s is read only"

*Cause:    An attempt was made to resize a data file in a tablespace that

          is read only.

*Action:   Change the tablespace to read/write and retry the resize operation.

Error starting at line 2 in command:

alter tablespace CHEN read/write

Error report:

SQL Error: ORA-02142: missing or invalid ALTER TABLESPACE option

02142. 00000 -  "missing or invalid ALTER TABLESPACE option"

*Cause:    A valid option was not present.

*Action:   Use one of the valid options

          offline, read only, read write, begin, end, no, force,

          retention guarantee and retention noguarantee.


从error信息中可以看出,read write是一种状态,但是没有明确指出这种状态属于online,前面是在OEM中操作,提示要把表空间online。

至此, 使用命令:alter tablespace CHEN read write;

成功了,表空间变成online的状态了。然后添加数据文件都正常了。


总结:对于基本的概念一定要理解清楚,alter tablesapce online在表空间是read only的情况下,并不能把表空间直接更改为可写的模式。只是online,online为可读,可切换数据文件,但写入是不行的。因此需要更改为read write。


若有高手们有其他更系统的建议,欢迎交流。