首页 > Linux操作系统 > Linux操作系统 > 临时文件在unix下的大小问题
近来看TOM的书.说临时文件在UNIX下会稀疏的创建,意思是在用到它们之前是不会真正的占有磁盘存储空间的.
来看TOM的这个例子, 以下是我机器上的测试情况:
!df">sys@RAC1>!df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 11258648 8925304 1761432 84% /
/dev/sda1 101086 8714 87153 10% /boot
none 134084 0 134084 0% /dev/shm
/dev/sda3 497861 78277 393880 17% /tmp
create">sys@RAC1>create temporary tablespace temp2 tempfile 'u01/app/oracle/oradata/rac1/temp2' size 2048M;
create temporary tablespace temp2 tempfile 'u01/app/oracle/oradata/rac1/temp2' size 2048M
*
ERROR at line 1:
ORA-01119: error in creating database file 'u01/app/oracle/oradata/rac1/temp2'
ORA-27040: file create error, unable to create file
Linux Error: 2: No such file or directory
create">sys@RAC1>create temporary tablespace temp2 tempfile '/u01/app/oracle/oradata/rac1/temp2' size 2048M;
Tablespace created.
!df">sys@RAC1>!df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 11258648 8925380 1761356 84% /
/dev/sda1 101086 8714 87153 10% /boot
none 134084 0 134084 0% /dev/shm
/dev/sda3 497861 78277 393880 17% /tmp
正如所说,一个2GB的文件一瞬间就创建成功了.
可以看到创建之前与创建之后磁盘空间情况只是增加了74kb,但ls却是2GB
sys@RAC1>! ls -l /u01/app/oracle/oradata/rac1/temp2
-rw-r----- 1 oracle oinstall 2147491840 Sep 10 02:57 /u01/app/oracle/oradata/rac1/temp2
在UNIX上,为了使其占有实际空间,我们可以使用cp来创建一个非稀疏文件(由于空间不足,所以我只创建了一个100M大小的文件):
[oracle@rac1 rac1]$ cp --sparse=never /u01/app/oracle/oradata/rac1/temp2 /u01/app/oracle/oradata/rac1/temp2_r
[oracle@rac1 rac1]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 11258648 9027900 1658836 85% /
/dev/sda1 101086 8714 87153 10% /boot
none 134084 0 134084 0% /dev/shm
/dev/sda3 497861 78277 393880 17% /tmp
[oracle@rac1 rac1]$
可以看到.这时候占用了实际的占用空间了.然后我们可以使temp tablespace来使用这个非稀疏文件.
drop">sys@RAC1>drop tablespace temp2;
Tablespace dropped.
create">sys@RAC1>create temporary tablespace temp2 tempfile '/u01/app/oracle/oradata/rac1/temp2_r' reuse;
Tablespace created.
这里我们就可以使用这个非稀疏文件了.
主要是为了避免了SA或DBA误认为磁盘空间还多而造成一些失误.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/104152/viewspace-139956/ ,如需转载,请注明出处,否则将追究法律责任。