Oracle undo 表空间不可用

  

  由于某次不小心操作,在切换表空间时没有成功,由于把undo的配置参数 undo_management值设置为MANUAL所以在启动数据库时没有报任何错误,但是给表插入数据时报错了,回滚段不可用的错误。然后查询了错误原因。

  

  1 首先看数据库中undo信息

  

SQL> show parameter undo;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string MANUAL
undo_retention integer 10800
undo_tablespace string UNDOTBS2

undo_tablespace 是UNDOTBS2,实际上已经被删除,因为参数 undo_management MANUAL,所以数据库可以正常启动。

 

2 查看数据库undo 数据文件

select file_name,tablespace_name,online_status
from dba_data_files
where tablespace_name like '%UNDO%';

FILE_NAME TABLESPACE_NAME ONLINE_STATUS
1 /home/oracle/oradata/UNDOTBS1.dbf UNDOTBS1 ONLINE

数据库中只有一个名为UNDOTBS1 undo表空间,很明显系统里undo 配置信息有误,导致undo表空间不可用,插入数据时报错。

 

3 重启数据库到mount状态修改undo 配置信息

SQL> startup mount;
ORACLE instance started.

Total System Global Area 450953216 bytes
Fixed Size 2214256 bytes
Variable Size 348128912 bytes
Database Buffers 96468992 bytes
Redo Buffers 4141056 bytes
Database mounted.

SQL> alter system set undo_management='AUTO'  scope=spfile;

  System altered.

  重启数据库到mount状态下查看undo配置信息

SQL> show parameter undo

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS2
SQL> show parameter undo_tablespace;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS2

  

  然后修改undo_tablespace 

SQL> alter system set undo_tablespace=UNDOTBS1;
alter system set undo_tablespace=UNDOTBS1
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-01219: database not open: queries allowed on fixed tables/views only

报数据库未打开的错误,于是打开数据库

SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced
ORA-30012: undo tablespace 'UNDOTBS2' does not exist or of wrong type
Process ID: 72674
Session ID: 1 Serial number: 3

又遇到新的错误,应该是修改了undo_management为AUTO然后启动时要检测对应的undo_tablespace,但是undo_tablespace 对应的 UNDOTBS2不存在,所以引起了一系列问题。

 

根据以往经验准备关闭数据库然后查看spfile关于undo表空间的配置是否正确,正确则采用spfile启动到mount状态,不正确则修改之后再使用spfile方式启动到mount状态,关闭数据库问题又来了

SQL> shutdown abort;
ORA-24324: service handle not initialized
ORA-01041: internal error. hostdef extension doesn't exist
SQL> shutdown immediate;
ORA-24324: service handle not initialized
ORA-01041: internal error. hostdef extension doesn't exist
SQL> show parameter undo;
ERROR:
ORA-03114: not connected to ORACLE

 

不管以哪种方式关闭,都不行,也不能查询参数信息,数据库处于异常状态,于是百度查询解决办法:

首先退出sqlplus然后设置一下,指定ORACLE_SID,进而提供了实例信息就可以解决问题。

SQL> exit;
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@oracledb ~]$ set ORACLE_SID=ORCL
[oracle@oracledb ~]$ sqlplus

SQL> shutdown abort;
ORACLE instance shut down.

进入sqlplus顺利关闭数据库,然后再去查看对应的spfile,/usr/oracle/app/admin/orcl/pfile/init.ora.95201623739,vim 进去查看关于undo信息的配置如果不正确要修改,主要是undo_tablespace修改为数据库存在且可用的undo表空间,信息如下:

undo_management=AUTO
undo_retention=10800
undo_tablespace=UNDOTBS1
"init.ora.95201623739" 58L, 1877C

 

修改之后采用spfile启动到mount状态下

SQL> startup mount pfile=/usr/oracle/app/admin/orcl/pfile/init.ora.95201623739;
ORACLE instance started.

数据库启动成功,查看undo配置信息。正确了。

SQL> show parameter undo;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 10800
undo_tablespace string UNDOTBS1

 

然后启动数据库到open状态,可以向表中插入数据了,不会再报回滚段不可用的错误了。

 

关于关闭数据库时遇到 ORA-24324 与ORA-01041错误,一般的解决的办法如下

  • 重启监听程序;
  • 重启sqlplus;
  • 登陆服务器本机重启数据库;

 

总结,在修改undo配置信息时,先修改了undo_management 为auto,undo_tablespace没有一起修改,导致重启之后系统会根据undo_tablespace的值配置为UNDOTBS2,但是这个表空间实际上是不存在的,所以启动过程发生异常。应该一起修改undo_management 与 undo_tablespace,然后重启数据库就不会产生之后一系列问题了。

 

 

 

  

原文地址:https://www.cnblogs.com/Latiny/p/7091339.html