首先看一下该错误的信息
[oracle@ymm ~]$ oerr ora 01555
01555, 00000, "snapshot too old: rollback segment number %s with name \"%s\" too small"
// *Cause: rollback records needed by a reader for consistent read are
//
overwritten by other writers
// *Action: If in Automatic Undo Management mode, increase undo_retention
// setting. Otherwise, use larger rollback segmentsoerr是可以在操作系统上使用的一条命令。我们可以用它来查看遇到的错误的相关信息。
ora-01555是与undo相关的一个错误。oracle会在对数据进行修改之前,先保存一份未修改的数据,这称为undo(将要修改的数据保存一份在undo中,为了保持数据一致性读)。undo信息存放在undo表空间中。按照事务隔离性要求,我们当前修改数据的事务还未结束,其他会话或者事务看不到我们修改后的数据,只能从undo中查看修改之前的数据,这就是一致性查询。但undo表空间中的空间也是循环使用的,只是undo会有一定的保留期限。如果某个事务想要查看的undo信息在undo表空间中不存在,就会出现快照太旧问题。
查看数据库undo信息SQL> show parameter undo;
undo 的默认管理模式为自动管理,一般不需要DBA进行干涉。undo_retention表示一个事务结束后,该事务生成的undo信息在undo表空间中保留的时间,默认为900秒。这个时间可以进行修改。如果想要强制保证undo信息的保留时间,需要制定参数guarantee。设置这个参数undo信息都会在undo表空间至少保留900秒,然后才被其他事务生成的undo信息覆盖。如果undo表空间中没有剩余空间,数据库中所有新事物都将失败。如果没有设置改参数,并且此时有批量数据在处理,导致undo表空间中最开始未结束的事务的undo信息被覆盖,就会报ORA-01555alter tablespace undotbs1 retention guarantee;
解决方法有两种:
扩大undo表空间
alter tablespace UNDOTBS1 add datafile '/u01/app/oracle/oradata/PROD/undotbs02.dbf' size 120M;
设置参数强制保留时间 guarantee UNDO默认的保留时间是15分钟(900秒),我们调整为1.5小时(5400秒)。 sql> alter system set undo_retention=5400; sql> alter tablespace undotbs1 retention guarantee;取消强制保留
sql> alter tablespace undotbs1 retention noguarantee;
