每一个Oracle版本,都会有很多新特性和技术推出。这些技术特性,在很大程度上都能改进Oracle运行效率和应用效果,或者提高我们日
每一个Oracle版本,都会有很多新特性和技术推出。这些技术特性,在很大程度上都能改进Oracle运行效率和应用效果,或者提高我们日常工作能力。
Temp表空间是Oracle表空间体系中一种很特殊的表空间对象。临时表空间主要用于支持临时表空间使用、排序分组动作空间溢出暂存等作用。我们对Temp的使用,大都是局限在空间分配和大小设置上。在11g有,有一系列针对Temp表空间的新特性,可以很大程度上帮助我们工作。
视图dba_temp_free_space是11g引入的一个新视图,用于描述临时表空间使用情况。
--------------------------------------分割线 --------------------------------------
相关阅读:
Oracle Undo 镜像数据探究
Oracle 回滚(ROLLBACK)和撤销(Undo)
Undo 表空间损坏导致无法open
Undo表空间失败的处理方法
Oracle Undo表空间重建与恢复
--------------------------------------分割线 --------------------------------------
SQL> select * from dba_temp_free_space;
TABLESPACE_NAME TABLESPACE_SIZE ALLOCATED_SPACE FREE_SPACE
--------------- --------------- --------------- ----------
TEMP 481296384 481296384 479199232
最近和一个朋友聊起其中allocated_space和free_space的含义,觉得很有意思。笔者决定通过一些实验来证明结论。
1、环境准备
笔者使用Oracle11gR2环境进行测试。
SQL> select * from v$version;
BANNER
------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
当前仅包括默认的Temp临时表空间。
SQL> select file_name, file_id, tablespace_name from dba_temp_files;
FILE_NAME FILE_ID TABLESPACE_NAME
------------------------------ ---------- ------------------------------
/u01/app/oradata/ORA11G/datafi 1 TEMP
le/o1_mf_temp_92t73qm8_.tmp
说明:为减少系统对实验结果影响,笔者创建全新的临时表空间,通过一系列的典型操作来,监控字段变化形态来证明实验结论。
2、表空间创建过程
首先我们创建临时表空间temptest。之前,我们检查磁盘空间空闲情况:
[oracle@SimpleLinux ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 48G 24G 22G 52% /
tmpfs 6.0G 256M 5.8G 5% /dev/shm
/dev/mapper/VolGrp01-lv1
194M 5.6M 179M 4% /voltest01
当前/目录对应大小48G,使用24G,有22G可用空间。下面创建表空间:
SQL> create temporary tablespace temptest tempfile size 5G
2 extent management local uniform size 1m;
Tablespace created
和创建同样大小数据表空间相比起来,执行创建临时表空间语句速度很快。之后查看磁盘空间情况。
[oracle@SimpleLinux ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 48G 24G 22G 52% /
tmpfs 6.0G 256M 5.8G 5% /dev/shm
/dev/mapper/VolGrp01-lv1
194M 5.6M 179M 4% /voltest01
容量上没有任何变化,,如果Oracle创建了5G空间,至少会显示在磁盘大小上。但是,从Oracle内部注册体系和文件系统中,我们都是可以看到临时文件的生成。
SQL> select file_name, file_id, tablespace_name from dba_temp_files;
FILE_NAME FILE_ID TABLESPACE_NAME
------------------------------ ---------- ---------------
/u01/app/oradata/ORA11G/datafi 1 TEMP
le/o1_mf_temp_92t73qm8_.tmp
/u01/app/oradata/ORA11G/datafi 2 TEMPTEST
le/o1_mf_temptest_9j80859z_.tm
p
[oracle@SimpleLinux datafile]$ ls -l | grep temptest
-rw-r----- 1 oracle oinstall 5368717312 Feb 19 08:55 o1_mf_temptest_9j80859z_.tmp
这个是Oracle临时数据文件的特性,Oracle临时文件和数据文件不同,创建之后是不直接占满空间的。我们都有这样的经历,创建一个很大的数据表空间,create/add过程依据不同的系统IO情况,是很消耗时间的。但是临时文件不是,一个上十几G的临时文件可以在很快的创建成功。
但是,这个过程其实是“障眼法”。Oracle虽然创建了临时文件,文件系统中也分配显示大小文件,但是空间却没有真正的分配。这在一些文献中称为“稀疏文件”,文件架构范围都在,但是没有实际写入过程。TempFile中的allocated,也就与稀疏文件有关。
注意:这就告诉我们系统部署人员,要注意临时文件的这个特性,不要以为磁盘上有很多的空间。
此时,我们观察视图dba_temp_free_space,结果如下:
SQL> select * from dba_temp_free_space;
TABLESPACE_NAME TABLESPACE_SIZE ALLOCATED_SPACE FREE_SPACE
--------------- --------------- --------------- ----------
TEMP 481296384 481296384 480247808
TEMPTEST 5368709120 1048576 5367660544
Tablespace_size为5368709120bytes大小,折合5G。这就是我们对临时表空间Temptest的定义值。

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
