首页 > 数据库 > Oracle > 海量数据迁移之通过shell估算数据量
| Tablespace | Init extent | Total MB | Free MB | Used MB |
| -------------------- | ---- | ------------ | ---------- | ----------- |
| DATAH01 | 16M | 572,113 | 135,408 | 436,705 |
| DATAL01 | 8M | 216,179 | 141,360 | 74,819 |
| DATAM01 | 4M | 291,840 | 85,280 | 206,560 |
| DATAS01 | 1M | 302,080 | 74,508 | 227,572 |
| INDXH01 | 4M | 174,033 | 96,256 | 77,777 |
| INDXM01 | 2M | 141,312 | 56,812 | 84,500 |
| INDXS01 | 128K | 240,640 | 72,241 | 168,399 |
| sum | 1,938,197 | 661,865 | 1,276,332 |
| INDEX_SIZE | TOTAL_SIZE | INDXH01 | INDXM01 | INDXS01 | |
| sum | 306093 | 62836 | 57302 | 185392 | |
| TABLE_SIZE | TOTAL_SIZE | DATAH01 | DATAL01 | DATAM01 | DATAS01 |
| sum | 546981 | 132944 | 72400 | 126508 | 215129 |
awk '{print "'\''" $1 "'\''" ","}' tablst |sed -e '/^$/d' -e '$s/.$//' > tablst.temp
table_list=`cat tablst.temp`
sqlplus -s xxxxxxx <
set pages 100
col table_name format a30
break on report
compute sum of total_size on report
compute sum of INDXH01 on report
compute sum of INDXM01 on report
compute sum of INDXS01 on report
select table_name,
sum(size_MB) total_size,
sum(decode(tablespace_name,'INDXH01', size_MB,0)) INDXH01,
sum(decode(tablespace_name,'INDXM01', size_MB,0)) INDXM01,
sum(decode(tablespace_name,'INDXS01', size_MB,0)) INDXS01
from (select idx.table_name, round(sum(seg.bytes/1024/1024)) size_MB,seg.tablespace_name from user_segments seg,user_indexes idx where seg.segment_name=idx.index_name and idx.table_name='MO1_MEMO' group by idx.table_name,seg.tablespace_name)
group by table_name;
EOF
rm tablst.temp
假设我们我们计算3个表。MEMO,CHARGE,CHARGE_REL,运行脚本后我们得到如下的清单,就很清楚的看到,哪些表占用了多少空间,在哪个表空间。
TABLE_NAME TOTAL_SIZE DATAH01 DATAL01 DATAM01 DATAS01
------------------------------ ---------- ---------- ---------- ---------- ----------
CHARGE 104720 104720 0 0 0
MEMO 81613 0 0 0 81613
CHARGE_REL 12672 12672 0 0 0
---------- ---------- ---------- ---------- ----------
sum 199005 117392 0 0 81613
通过如下的脚本来估算索引的表空间使用情况。
awk '{print "'\''" $1 "'\''" ","}' tablst |sed -e '/^$/d' -e '$s/.$//' > tablst.temp
table_list=`cat tablst.temp`
sqlplus -s xxxx <
set pages 100
col table_name format a30
break on report
compute sum of total_size on report
compute sum of DATAH01 on report
compute sum of DATAH01 on report
compute sum of DATAL01 on report
compute sum of DATAM01 on report
compute sum of DATAS01 on report
select table_name,
sum(size_MB) total_size,
sum(decode(tablespace_name,'DATAH01', size_MB,0)) DATAH01,
sum(decode(tablespace_name,'DATAL01', size_MB,0)) DATAL01,
sum(decode(tablespace_name,'DATAM01', size_MB,0)) DATAM01,
sum(decode(tablespace_name,'DATAS01', size_MB,0)) DATAS01
from (select segment_name table_name, round(sum(bytes/1024/1024)) size_MB,tablespace_name from user_segments where segment_name in ($table_list) group by segment_name,tablespace_name)
group by table_name;
EOF
rm tablst.temp
运行后得到的如下的一个清单,就可以看到表对应索引的存储情况。
TABLE_NAME TOTAL_SIZE INDXH01 INDXM01 INDXS01
------------------------------ ---------- ---------- ---------- ----------
CHARGE 27004 21620 0 5384
CHARGE_REL 28868 28868 0 0
MEMO 33999 0 0 33710
---------- ---------- ---------- ----------
sum 89871 50488 0 39094
得到了如上的列表,需要评估数据量的情况就有思路了。
可以基于当前数据库中的剩余空间来排查目前的空间是否足够,如果不够需要添加多少。
| Tablespace | Init extent | Total MB | Free MB | Used MB |
| -------------------- | ---- | ------------ | ---------- | ----------- |
| DATAH01 | 16M | 572,113 | 135,408 | 436,705 |
| DATAL01 | 8M | 216,179 | 141,360 | 74,819 |
| DATAM01 | 4M | 291,840 | 85,280 | 206,560 |
| DATAS01 | 1M | 302,080 | 74,508 | 227,572 |
| INDXH01 | 4M | 174,033 | 96,256 | 77,777 |
| INDXM01 | 2M | 141,312 | 56,812 | 84,500 |
| INDXS01 | 128K | 240,640 | 72,241 | 168,399 |
| sum | 1,938,197 | 661,865 | 1,276,332 |
INDXM01 +50G
INDXS01 +100G
DATAM01 +50G
DATAS01 +100G
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29900508/viewspace-1275859/ ,如需转载,请注明出处,否则将追究法律责任。