【性能优化】手工分配区

 手工分配区
适用于批量数据加载:当大批量写入数据的时候,为了避免自动分配区所带来的性能开销, 那么可以尝试手动一次性增加足够大的区, 从而避免了自动分配区所带来的等待。

 

1) 创建测试表空间及表

SYS@ORA11GR2>create tablespace ts_users datafile '/u01/app/oracle/oradata/ORA11GR2/ts_users01.dbf' size 100m,'/u01/app/oracle/oradata/ORA11GR2/ts_users02.dbf' size 100m;

 

Tablespace created.

 

SYS@ORA11GR2>create table t1 tablespace ts_users as select * from all_objects;

 

Table created.

 

2) 查询区分配的数量大小

SYS@ORA11GR2>select bytes,count(*) from user_extents where segment_name='T1' group by bytes order by 1;

 

     BYTES   COUNT(*)

---------- ----------

     65536         16

   1048576          9

 

3) 查询数据文件已使用了多少

SYS@ORA11GR2>COL TABLESPACE_NAME FOR A10

SYS@ORA11GR2>COL FILE_NAME FOR A50

SYS@ORA11GR2>select d.tablespace_name, d.file_name, d.total - t.free used_m       

  2  from (select tablespace_name,                                        

  3  file_name,                                                           

  4  file_id,                                                             

  5  bytes / 1024 / 1024 total                                            

  6  from dba_data_files                                                  

  7  where tablespace_name = 'TS_USERS') d,                               

  8  (select file_id, bytes / 1024 / 1024 free                            

  9  from dba_free_space                                                  

 10  where tablespace_name = 'TS_USERS') t                                

 11  where d.file_id = t.file_id;                                          

 

TABLESPACE FILE_NAME                                              USED_M

---------- --------------------------------------------------

TS_USERS /u01/app/oracle/oradata/ORA11GR2/ts_users01.dbf           6

TS_USERS /u01/app/oracle/oradata/ORA11GR2/ts_users02.dbf           6

 

4) ts_users02.dbf 数据文件上手工分配大小为50M 的区

SYS@ORA11GR2>alter table t1 allocate extent (size 50M datafile '/u01/app/oracle/oradata/ORA11GR2/ts_users02.dbf');

 

Table altered.

 

5) 再次查询区分配的数量及大小

SYS@ORA11GR2>select bytes,count(*) from user_extents where segment_name='T1' group by bytes order by 1;

 

     BYTES   COUNT(*)

---------- ----------

     65536         16

   1048576         59

 

6) 再次查看数据文件的剩余空间, 很明显 ts_users02.dbf 数据文件已经使用 56M而与 ts_users01.dbf 数据文件明显分配不均也是因为我们手工分配区所导致的。 其中手工分配的较大的空闲区, 正好用于大量的数据写入, 在写入的过程中,避免了由于自动分配区所对性能的影响。

SYS@ORA11GR2>select d.tablespace_name, d.file_name, d.total - t.free used_m                   

  2  from (select tablespace_name,                                                    

  3  file_name,                                                                       

  4  file_id,                                                                          

  5  bytes / 1024 / 1024 total                                                        

  6  from dba_data_files                                                              

  7  where tablespace_name = 'TS_USERS') d,                                           

  8  (select file_id, bytes / 1024 / 1024 free                                        

  9  from dba_free_space                                                              

 10  where tablespace_name = 'TS_USERS') t                                            

 11  where d.file_id = t.file_id;                                                     

 

TABLESPACE FILE_NAME                                              USED_M

---------- --------------------------------------------------

TS_USERS /u01/app/oracle/oradata/ORA11GR2/ts_users01.dbf           6

TS_USERS /u01/app/oracle/oradata/ORA11GR2/ts_users02.dbf          56

 

查看:

SYS@ORA11GR2>select file_id,tablespace_name,file_name,bytes/1024/1024 total from dba_data_files where tablespace_name ='TS_USERS';

 

FILE_ID TABLESPACE FILE_NAME                                               TOTAL

---------- --------------------------------------------------

      6 TS_USERS   /u01/app/oracle/oradata/ORA11GR2/ts_users01.dbf           100

      7 TS_USERS   /u01/app/oracle/oradata/ORA11GR2/ts_users02.dbf           100

 

SYS@ORA11GR2>select file_id,bytes/1024/1024 free from dba_free_space where tablespace_name='TS_USERS';        

 

FILE_ID       FREE

------- ----------

      6         94

      7         44

 

 


请使用浏览器的分享功能分享到微信等