表空间扩容

一、查看表空间大小

查看临时表空间大小

set linesize 120 pagesize 999
column tbs_name format a20;
select a.name "tbs_name",
       round(a.bytes /1024/1024 , 2) "tbs_size(mbytes)",
       round(((a.blocks - nvl(b.used_blocks,0))/a.blocks)*a.bytes / 1024/1024,2)             
       "tbs_free(mbytes)",
       round((nvl(b.used_blocks,0) / a.blocks)*a.bytes /1024/1024 ,2) "tbs_used(mbytes)",
       round((nvl(b.used_blocks,0) / a.blocks)*100,2) "percent %"
from (select t.NAME, sum(f.BYTES) as bytes, sum(f.BLOCKS) as blocks
       from v$tempfile f, v$tablespace t
       where t.TS#=f.TS#
       group by t.name) a,
       (select TABLESPACE_NAME, sum(USED_BLOCKS) as used_blocks
       from gv$sort_segment
       group by TABLESPACE_NAME)b
where a.name = b.tablespace_name(+)
order by length(a.name), a.name;

查看非临时表空间大小
 

set linesize 200

select a.tablespace_name,
       trunc(sum(a.tots)/1024/1024,2)tot_size_mb,
       round(sum(a.sumb)/1024/1024,2)tot_free_mb,
       round(sum(a.sumb)*100/sum(a.tots),2) pct_free,
       round(sum(a.largest)/1024/1024,2)max_free_mb
from (select tablespace_name,
        0 tots,
        sum(bytes)sumb,
        max(bytes)largest,
        count(*)chunks
      from dba_free_space a
      group by tablespace_name
      union 
      select tablespace_name, sum(bytes) tots,0,0,0
      from dba_data_files
      group by tablespace_name)a
group by a.tablespace_name order by 4;

二、查看表空间路径

临时表空间

select * from dba_temp_files;

非临时表空间

select * from dba_data_files;

三、表空间扩容

数据文件的大小是由db_block_size决定的,oracle默认的一般都是8kb大小,Oracle表空间数据文件每个数据文件最多只能包含2^22个数据块。所以就是8K*2^22 = 32G。

这里为了方便就取30G,方便取整。

如果需要添加的容量没超过30G,那就只需要添加一次。

如果超过了30G,可以分成多次来添加。

也可以利用脚本在后台批量执行:

这里以扩容120G为例

我们可以先把下面的内容放入脚本中,然后执行脚本。

sqlplus "/ as sysdba" <<EOF
set timing on
alter tablespace  tablespacename(此处为表空间名称)add datafile '+DATA'(此处为表空间路径) size 30G autoextend off;
alter tablespace  tablespacename(此处为表空间名称)add datafile '+DATA'(此处为表空间路径) size 30G autoextend off;
alter tablespace  tablespacename(此处为表空间名称)add datafile '+DATA'(此处为表空间路径) size 30G autoextend off;
alter tablespace  tablespacename(此处为表空间名称)add datafile '+DATA'(此处为表空间路径) size 30G autoextend off;
EOF

nohup sh tab_create.sh &

临时表空间的扩容速度要比非临时的快,可以不用脚本直接在sqlplus里面执行扩容语句

alter tablespace  tablespacename(此处为表空间名称)add tempfile '+DATA'(此处为表空间路径) size 30G autoextend off

需要注意的是

临时表空间的是tempfile,非临时表空间的是datafile。


版权声明:本文为qq_40699063原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。