一位朋友说他们压测的应用,前几天都正常,昨天执行的时候,报了如下错误,但是今天没出现,DBA说他们某条SQL占用临时表空间太多了,昨天还给扩了10个G的临时表空间容量,

ORA-01652: 无法通过 128 (在表空间 TEMP 中)扩展 temp 段

因为牵扯到一些内部数据,所以有些内容就文字叙述,不截图了。

猜测1:SQL导致临时表空间不足?

看了下这条SQL,500多行,大量使用了dblink,但从执行计划看,虽然用到了临时段空间,成本消耗并不大,而且现象是只有昨天出现了这个问题,很难下定论,就是这条SQL导致的。

Oracle的alert.log中会对ORA-01652错误的内容记录trace日志,看了一些,发现其中涉及到很多的SQL,不仅是上述DBA反馈的这条。说明在这个时间段,很多SQL都受影响。

猜测2:用户使用了其他的临时表空间?

因为可以给用户指定不同的临时表空间,是否有可能该用户未使用默认的,而扩容的是默认的临时表空间?

通过检索dba_users,该用户使用的就是默认的临时表空间TEMP,而且该数据库就只有一个临时表空间。

猜测3:临时表空间即使扩容了,确实不够?

看下当前表空间的用度,发现TEMP临时表空间只有300多MB,按上面说的,扩容过10G,现在的容量,应该至少10G以上。

我们还是从alert.log日志中寻找一些端倪。

看到执行扩容的操作,有以下几种,

(1) 第1条"扩容"操作

alter tablespace TEMP add datafile '/oradata/xxx/temp01.dbf' size 5G autoextend on maxsize unlimited
ORA-3217 signalled during: alter tablespace TEMP add datafile '/oradata/xxx/temp01.dbf' size 5G autoextend on maxsize unlimited

ORA-3217解释如下,很明显,增加临时表空间的操作存在语法错误,因此扩容失败,

03217, 00000, "invalid option for alter of TEMPORARY TABLESPACE"
// *Cause: invalid option for alter of temporary tablespace was specified
// *Action: Specify one of the valid options: ADD TEMPFILE,
//          TEMPFILE ONLINE, TEMPFILE OFFLINE

(2) 第2条"扩容"操作

alter tablespace tempfile add datafile '/oradata/xxx/temp01.dbf' size 5G autoextend on maxsize unlimited
ORA-959 signalled during: alter tablespace tempfile add datafile '/oradata/xxx/temp01.dbf' size 5G autoextend on maxsize unlimited

ORA-959解释如下,不存在tempfile这个名称的临时表空间,

00959, 00000, "tablespace '%s' does not exist"
// *Cause:
// *Action:

(3) 第3条"扩容"操作

alter database datafile '/oradata/xxx/temp01.dbf' autoextend on
ORA-1516 signalled during: alter database datafile '/oradata/xxx/temp01.dbf' autoextend onalter database datafile '/oradata/xxx/temp02.dbf' autoextend on
ORA-1516 signalled during: alter database datafile '/oradata/xxx/temp02.dbf' autoextend on

ORA-1516解释如下,前半部分的语法是错误的,

01516, 00000, "nonexistent log file, data file, or temporary file \"%s\" in the current container"
// *Cause:  An attempt was made to use ALTER DATABASE to rename
//          a log file, data file, or temporary file; or to change attributes
//          of a data file or temporary file (for example, resize, autoextend,
//          online or offline); or to re-create or move a data file.
//          The attempt failed because the specified file
//          is not known to the database's control file
//          or the current container or is not of a type
//          supported by the request.
// *Action: Specify the name or number of an existing file
//          of the correct type, as appropriate.
//          Check the relevant V$ table for a list of possible files.

(4) 第4条"扩容"操作

alter tablespace temp add tempfile '/oradata/xxx/temp01.dbf' size 5G
ORA-1537 signalled during: alter tablespace temp add tempfile '/oradata/xxx/temp01.dbf' size 5G

ORA-1537解释如下,temp01.dbf数据文件就是当前临时表空间TEMP所对应的文件,因此增加该文件,会提示重复,

01537, 00000, "cannot add file '%s' - file already part of database"
// *Cause:  During CREATE or ALTER TABLESPACE, a file being added is already
//         part of the database.
// *Action:  Use a different file name.

几次增加临时表空间的操作,都是因为各种原因没加成,直到执行了这条,

alter tablespace temp add tempfile '/oradata/xxx/temp02.dbf' size 10G
Completed: alter tablespace temp add tempfile '/oradata/xxx/temp02.dbf' size 10G

所以在未增加成功之前,猜测确实临时表空间是不足的,因为很多应用共用这个临时表空间,所以受影响的SQL应该有很多,而这个应用反馈的语句,只是其中之一,当增加成功后,才会恢复正常,从alert.log看,确实没继续抛出这个异常了。

但是,既然增加了10G的空间了,为什么开始检索的时候,临时表空间容量只有300MB?还是从alert.log找线索,他执行了这条,对临时表空间

alter tablespace temp shrink space
Completed: alter tablespace temp shrink space

之前理解,一般只是对表才能做shrink space,起到收缩空间的作用,但这个是对表空间执行的,实际上官方文档,提到了这种操作,特意指出"Shrink the amount of space a temporary tablespace or a temp file is taking",对临时表空间才会起作用,

SHRINK SPACE Clause
This clause is valid only for temporary tablespaces. It lets you reduce the amount of space the tablespace is taking. In the optional KEEP clause, the size_clause defines the lower bound that a tablespace can be shrunk to. It is the opposite of MAXSIZE for an autoextensible tablespace. If you omit the KEEP clause, then the database will attempt to shrink the tablespace as much as possible as long as other tablespace storage attributes are satisfied

Managing Space in a Temporary Tablespace: Example
The following statement manages the space in the temporary tablespace created in "Creating a Temporary Tablespace: Example" using the SHRINK SPACE clause. The KEEP clause is omitted, so the database will attempt to shrink the tablespace as much as possible as long as other tablespace storage attributes are satisfied.

ALTER TABLESPACE temp_demo SHRINK SPACE;

P.S.https://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_3002.htm#SQLRF01002

因此,临时表空间的容量实际被收缩了。

针对这个案例,能借鉴到的还是很多的,当出现问题时,除了一些常规的判断路径外,还可以大胆猜测,逐一论断。

如果您认为这篇文章有些帮助,还请不吝点下文章末尾的"点赞"和"在看",或者直接转发pyq,

近期更新的文章:

《MySQL的TIMESTAMP数据类型》

《你知道雨的类型有几种?》

《最近碰到的一些问题》

《小白学习MySQL - Derived Table》

《麒麟OS和龙芯环境编译安装GreatSQL》

近期的热文:

《"红警"游戏开源代码带给我们的震撼》

文章分类和索引:

《公众号1000篇文章分类和索引》

Oracle一个诡异的临时表空间不足的问题相关推荐

  1. oracle查看创建的临时表空间,Oracle临时表空间的创建和查看

    作者:雨竹清风 临时表空间是作为排序操作使用的.临时表空间中的排序段是在实例启动后,当有第一个排序操作时创建的. 1.查看在数据库中临时表空间的名称和数量,状态等. SQL> desc dba_ ...

  2. 清空临时表oracle,【Oracle相关】Oracle中如何清空临时表空间

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 [问题]数据库临时表空间占用空间太大,暂用大量磁盘空间. [处理]清空临时表空间 Oracle1.启动数据库 startup 2.查看当前的数据库默认表空 ...

  3. oracle 临时表空间的增删改查

    oracle 临时表空间的增删改查 1.查看临时表空间 (dba_temp_files视图)(v_$tempfile视图) select tablespace_name,file_name,bytes ...

  4. oracle 12创建一个表,oracle 12 c 创建表空间,用户名,及表

    -----------------------------------------12C start------------------------------------------- -- 创建表 ...

  5. Oracle Temp临时表空间及其故障处理

    Oracle Temp临时表空间及其故障处理 Oracle 11g中Temp临时表空间.文件的新特性 临时表空间是Oracle体系结构中比较特殊的结构.通常情境下,数据库使用者只需要设置对应的临时表空 ...

  6. Oracle中关于临时表空间无法释放问题

    一.日常工作中出现的"灵异事件" 利用BI工具在进行整体流程跑批的时候,一段时间就会报错:临时表空间不足 生产环境中为了保证系统的稳定,一般不采取重启数据库的方式.所以扩充表空间或 ...

  7. oracle 更换临时表空间,重建及切换临时表空间

    來源網絡 1.查看临时表空间(dba_temp_files视图)(v_$tempfile视图) select tablespace_name,file_name,bytes/1024/1024 fil ...

  8. 130108还原临时表空间

    临时表空间由于其特殊性,不能也不需要备份,在临时表空间出错时或者还原数据库到新环境需要新建临时表空间时,我们使用两种方法对其进行还原: 方法1)建立新的临时表空间文件,删除受损的临时表空间旧文件: 方 ...

  9. oracle创建用户、表空间、临时表空间、分配权限步骤详解

    首先登陆管理员账号,或者有DBA权限的用户,接下来依次: --查询所有用户 select * from dba_users; --创建新用户 create user gpmgt identified ...

最新文章

  1. 乐乐茶完成近2亿元Pre-A轮融资,祥峰投资领投
  2. 作业6 分析项目的NABCD和项目的产品Backlog
  3. crontab FAQ
  4. SQLite移植手记1
  5. [react] 怎么防止HTML被转义?
  6. java9默认收集器_Oracle提议将G1作为Java9的默认垃圾收集器
  7. 科天云会议产品升级,打造企业数字化转型办公协同新基建
  8. 仿百度文库实现文档在线预览
  9. 数据结构—快速排序及其实现思想分而治之DC(思维导图版)
  10. 全卷积网络 FCN 详解(很好,详看)
  11. 第一章 行列式 第六节 行列式按行(列)展开
  12. 20190905层析分析法matlab,未通过一致性检验时,重新构造判断矩阵再计算
  13. outlook2007 有一个程序正试图以您的名义自动发送电子邮件
  14. 第四届全国大学生GIS应用技能大赛试题参考答案(上午第2套)
  15. winpe linux系统安装win7,WINPE+LINUX+DOS 完美者U盘维护系统V8.6 及安装方法
  16. vue实现列表无缝滚动
  17. git 简单命令使用
  18. SAP PR采购申请修改BAPI报错
  19. linux中524端口,liunx下攻击分析及如何通过交换机封端口
  20. 美国第一个设置计算机的学校,美国计算机专业院校

热门文章

  1. 路由 OSPF常见4种网络类型MA、P2P、NBMA、P2MP、OSPF报头字段信息简介。
  2. 在线支付——如何防止订单重复支付?
  3. GetContactInfoUtils(一个获取手机联系人名称,电话,头像的工具类)
  4. 整理一篇很全面的iOS面试题
  5. while、do...while、for循环的使用
  6. vscode 一直显示Load project: XXXX,保存时提示“从 “‘Vetur‘, ‘Vue Language Features (Volar)‘“ (configure)中获取代码操作”
  7. linux服务器黑客攻防
  8. Android 集成 Agora SDK 快速体验 RTC 版多人视频聊天|掘金技术征文
  9. timestamp 6 mysql_Oracle timestamp(6)运用
  10. Java爬虫初学——爬取BT电影天堂电影的磁力链接并筛选下载