Oracle tablespace maxsize解析

在学习和使用的过程中,经常会出现一些简单的概念,了解了,也就不深究了。

但是在很多时候,忽然发现,并不能完全深入的理解其含义和功能。

近日使用到maxsize参数,突然不确定它最终限制的是什么,所以做了一个实验,测试其真正的功能和含义。

下面就是我的测试步骤和最后的总结:

 

1. 创建一个500k的自动扩展10m最大100M的表空间
sys@R11203> CREATE TABLESPACE tbs_02_test  DATAFILE '/opt/oracle/oradata/R11203/tbs_f5_test.dbf' SIZE 500K REUSE  AUTOEXTEND ON NEXT 10m MAXSIZE 100M;

Tablespace created.

2. 可以通过下面名称查询这个数据文件的属性
sys@R11203> select FILE_NAME,TABLESPACE_NAME,MAXBYTES,MAXBLOCKS,USER_BYTES from dba_data_files where TABLESPACE_NAME='TBS_02_TEST';

FILE_NAME                                          TABLESPACE_NAME                  MAXBYTES  MAXBLOCKS USER_BYTES
-------------------------------------------------- ------------------------------ ---------- ---------- ----------
/opt/oracle/oradata/R11203/tbs_f5_test.dbf         TBS_02_TEST                     104857600      12800     458752

3. 创建test表到这个表空间中
sys@R11203> CREATE TABLE test TABLESPACE TBS_02_TEST AS (SELECT * FROM dba_objects);                                           
Table created.

4. 连续插入数据,来填满表空间
sys@R11203> insert into test select * from test;

83710 rows created.

sys@R11203> commit;

5. 查询该表大小,单位M

sys@R11203> select segment_name, bytes/1024/1024 used_size from user_segments where segment_name = 'TEST';

SEGMENT_NAME                                                                       USED_SIZE
--------------------------------------------------------------------------------- ----------
TEST                                                                                      20

6. 再次插入
sys@R11203> insert into test select * from test;
commit;
167420 rows created.

sys@R11203>

Commit complete.

7. 目前该表大小达到39M
sys@R11203> select segment_name, bytes/1024/1024 used_size from user_segments where segment_name = 'TEST';

SEGMENT_NAME                                                                       USED_SIZE
--------------------------------------------------------------------------------- ----------
TEST                                                                                      39

8. 当前表空间已经使用42M
sys@R11203>  select FILE_NAME,TABLESPACE_NAME,MAXBYTES,MAXBLOCKS,USER_BYTES from dba_data_files where TABLESPACE_NAME='TBS_02_TEST';

FILE_NAME                                          TABLESPACE_NAME                  MAXBYTES  MAXBLOCKS USER_BYTES
-------------------------------------------------- ------------------------------ ---------- ---------- ----------
/opt/oracle/oradata/R11203/tbs_f5_test.dbf         TBS_02_TEST                     104857600      12800   42401792

9. 继续插入
sys@R11203> insert into test select * from test;
commit;

10. 查询,达到79.5M

sys@R11203> sys@R11203>  select segment_name, bytes/1024/1024 used_size from user_segments where segment_name = 'TEST';

SEGMENT_NAME                                                                       USED_SIZE
--------------------------------------------------------------------------------- ----------
TEST                                                                                    79.5

11. 表空间达到84M
sys@R11203>  select FILE_NAME,TABLESPACE_NAME,MAXBYTES,MAXBLOCKS,USER_BYTES from dba_data_files where TABLESPACE_NAME='TBS_02_TEST';

FILE_NAME                                          TABLESPACE_NAME                  MAXBYTES  MAXBLOCKS USER_BYTES
-------------------------------------------------- ------------------------------ ---------- ---------- ----------
/opt/oracle/oradata/R11203/tbs_f5_test.dbf         TBS_02_TEST                     104857600      12800   84344832

12. 再次插入,失败,无法扩展表空间
sys@R11203> insert into test select * from test;
commit;
insert into test select * from test;
commit;
insert into test select * from test
*
ERROR at line 1:
ORA-01653: unable to extend table SYS.TEST by 1024 in tablespace TBS_02_TEST

sys@R11203>
Commit complete.

sys@R11203> insert into test select * from test
*
ERROR at line 1:
ORA-01653: unable to extend table SYS.TEST by 1024 in tablespace TBS_02_TEST

13. 查询表空间,已经到达maxsize的值
sys@R11203>  select FILE_NAME,TABLESPACE_NAME,MAXBYTES,MAXBLOCKS,USER_BYTES from dba_data_files where TABLESPACE_NAME='TBS_02_TEST';

FILE_NAME                                          TABLESPACE_NAME                  MAXBYTES  MAXBLOCKS USER_BYTES
-------------------------------------------------- ------------------------------ ---------- ---------- ----------
/opt/oracle/oradata/R11203/tbs_f5_test.dbf         TBS_02_TEST                     104857600      12800  104792064

14. 当前表95.5M
sys@R11203>  select segment_name, bytes/1024/1024 used_size from user_segments where segment_name = 'TEST';

SEGMENT_NAME                                                                       USED_SIZE
--------------------------------------------------------------------------------- ----------
TEST                                                                                    95.5

15. 在不能自动扩展的情况下,如果手动介入呢,是否可以继续扩展表空间的数据文件大小呢?
测试结果是,可以继续手工扩展表空间
sys@R11203>  alter database datafile '/opt/oracle/oradata/R11203/tbs_f5_test.dbf' resize 300m;                                 
Database altered.

16. 当前表空间大小为300M
sys@R11203> select FILE_NAME,TABLESPACE_NAME,MAXBYTES,MAXBLOCKS,USER_BYTES from dba_data_files where TABLESPACE_NAME='TBS_02_TEST';

FILE_NAME                                          TABLESPACE_NAME                  MAXBYTES  MAXBLOCKS USER_BYTES
-------------------------------------------------- ------------------------------ ---------- ---------- ----------
/opt/oracle/oradata/R11203/tbs_f5_test.dbf         TBS_02_TEST                     104857600      12800  314507264

sys@R11203>

17. 可以继续向test表插入数据

sys@R11203> insert into test select * from test;
commit;

669680 rows created.

sys@R11203>
Commit complete.

18. 目前表已经达到159.5M
sys@R11203> select segment_name, bytes/1024/1024 used_size from user_segments where segment_name = 'TEST';

SEGMENT_NAME                                                                       USED_SIZE
--------------------------------------------------------------------------------- ----------
TEST                                                                                   159.5

 

19. 再次插入数据,目前表大小达到295.5M,

sys@R11203> select segment_name, bytes/1024/1024 used_size from user_segments where segment_name = 'TEST';

SEGMENT_NAME
--------------------------------------------------------------------------------
USED_SIZE
----------
TEST
     295.5

 

20. 表空间已经不能自动扩展,只有手工介入来增加表空间大小:

sys@R11203>  insert into test select * from test;
insert into test select * from test
             *
ERROR at line 1:
ORA-01653: unable to extend table SYS.TEST by 1024 in tablespace TBS_02_TEST

 

总结:
maxsize值只是限制auto extend的,在到达之前设定的maxsize大小之后,就不能自动扩展了,但是并不是说这样,表空间就不能扩展了,可以继续手动扩展数据文件大小。
同时,我们也可以通过增加数据文件来达到扩展表空间的目的。

你可能感兴趣的:(oracle,空间)