关于dba_temp_free_space的allocated_space和free_space
每一个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的定义值。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.
