查看表或者索引空间使用的函数---(转载)

本文介绍了一个用于检查数据库中表或索引空间使用的PL/SQL过程。该过程能够显示总块数、未使用块数等信息,并可根据是否已分析过segment提供更详细的空间使用情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是个查看表或者索引空间使用的函数,使用很方便。

create or replace procedure show_space    
( p_segname_1 in varchar2,    
p_space in varchar2 default 'MANUAL',    
p_type_1 in varchar2 default 'TABLE' ,    
p_analyzed in varchar2 default 'N',    
p_owner_1 in varchar2 default user)    
as    
p_segname varchar2(100);    
p_type varchar2(10);    
p_owner varchar2(30);    
  
l_unformatted_blocks number;    
l_unformatted_bytes number;    
l_fs1_blocks number;    
l_fs1_bytes number;    
l_fs2_blocks number;    
l_fs2_bytes number;    
l_fs3_blocks number;    
l_fs3_bytes number;    
l_fs4_blocks number;    
l_fs4_bytes number;    
l_full_blocks number;    
l_full_bytes number;    
  
l_free_blks number;    
l_total_blocks number;    
l_total_bytes number;    
l_unused_blocks number;    
l_unused_bytes number;    
l_LastUsedExtFileId number;    
l_LastUsedExtBlockId number;    
l_LAST_USED_BLOCK number;    
  
procedure p( p_label in varchar2, p_num in number )    
is    
begin    
dbms_output.put_line( rpad(p_label,40,'.') ||    
p_num );    
end;    
begin    
p_segname := upper(p_segname_1); -- rainy changed    
p_owner := upper(p_owner_1);    
p_type := p_type_1;    
  
if (p_type_1 = 'i' or p_type_1 = 'I') then --rainy changed    
p_type := 'INDEX';    
end if;    
  
if (p_type_1 = 't' or p_type_1 = 'T') then --rainy changed    
p_type := 'TABLE';    
end if;    
  
if (p_type_1 = 'c' or p_type_1 = 'C') then --rainy changed    
p_type := 'CLUSTER';    
end if;    
  
  
dbms_space.unused_space    
( segment_owner => p_owner,    
segment_name => p_segname,    
segment_type => p_type,    
total_blocks => l_total_blocks,    
total_bytes => l_total_bytes,    
unused_blocks => l_unused_blocks,    
unused_bytes => l_unused_bytes,    
LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,    
LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,    
LAST_USED_BLOCK => l_LAST_USED_BLOCK );    
  
if p_space = 'MANUAL' or (p_space <> 'auto' and p_space <> 'AUTO') then    
dbms_space.free_blocks    
( segment_owner => p_owner,    
segment_name => p_segname,    
segment_type => p_type,    
freelist_group_id => 0,    
free_blks => l_free_blks );    
  
p( 'Free Blocks', l_free_blks );    
end if;    
  
p( 'Total Blocks', l_total_blocks );    
p( 'Total Bytes', l_total_bytes );    
p( 'Unused Blocks', l_unused_blocks );    
p( 'Unused Bytes', l_unused_bytes );    
p( 'Last Used Ext FileId', l_LastUsedExtFileId );    
p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );    
p( 'Last Used Block', l_LAST_USED_BLOCK );    
  
  
/*IF the segment is analyzed */    
if p_analyzed = 'Y' then    
dbms_space.space_usage(segment_owner => p_owner ,    
segment_name => p_segname ,    
segment_type => p_type ,    
unformatted_blocks => l_unformatted_blocks ,    
unformatted_bytes => l_unformatted_bytes,    
fs1_blocks => l_fs1_blocks,    
fs1_bytes => l_fs1_bytes ,    
fs2_blocks => l_fs2_blocks,    
fs2_bytes => l_fs2_bytes,    
fs3_blocks => l_fs3_blocks ,    
fs3_bytes => l_fs3_bytes,    
fs4_blocks => l_fs4_blocks,    
fs4_bytes => l_fs4_bytes,    
full_blocks => l_full_blocks,    
full_bytes => l_full_bytes);    
dbms_output.put_line(rpad(' ',50,'*'));    
dbms_output.put_line('The segment is analyzed');    
p( '0% -- 25% free space blocks', l_fs1_blocks);    
p( '0% -- 25% free space bytes', l_fs1_bytes);    
p( '25% -- 50% free space blocks', l_fs2_blocks);    
p( '25% -- 50% free space bytes', l_fs2_bytes);    
p( '50% -- 75% free space blocks', l_fs3_blocks);    
p( '50% -- 75% free space bytes', l_fs3_bytes);    
p( '75% -- 100% free space blocks', l_fs4_blocks);    
p( '75% -- 100% free space bytes', l_fs4_bytes);    
p( 'Unused Blocks', l_unformatted_blocks );    
p( 'Unused Bytes', l_unformatted_bytes );    
p( 'Total Blocks', l_full_blocks);    
p( 'Total bytes', l_full_bytes);    
  
end if;    
  
end;   
  
/   
  

 


ASSM 类型的表

SQL> exec show_space('t','auto');
Total Blocks............................512
Total Bytes.............................4194304
Unused Blocks...........................78
Unused Bytes............................638976
Last Used Ext FileId....................9
Last Used Ext BlockId...................25608
Last Used Block.........................50

PL/SQL procedure successfully completed.


ASSM 类型的索引


SQL> exec show_space('t_index','auto','i');
Total Blocks............................80
Total Bytes.............................655360
Unused Blocks...........................5
Unused Bytes............................40960
Last Used Ext FileId....................9
Last Used Ext BlockId...................25312
Last Used Block.........................3

PL/SQL procedure successfully completed.


对analyze 过的segment 可以这样

SQL> exec show_space('t','auto','T','Y');
Total Blocks............................512
Total Bytes.............................4194304
Unused Blocks...........................78
Unused Bytes............................638976
Last Used Ext FileId....................9
Last Used Ext BlockId...................25608
Last Used Block.........................50
*************************************************
The segment is analyzed
0% -- 25% free space blocks.............0
0% -- 25% free space bytes..............0
25% -- 50% free space blocks............0
25% -- 50% free space bytes.............0
50% -- 75% free space blocks............0
50% -- 75% free space bytes.............0
75% -- 100% free space blocks...........0
75% -- 100% free space bytes............0
Unused Blocks...........................0
Unused Bytes............................0
Total Blocks............................418
Total bytes.............................3424256

PL/SQL procedure successfully completed.

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

 

自己试了老有错误,帮忙鉴定一下。

题目: 热带气旋利奇马中心(海平面气压最低值)所在位置的500hPa相对湿度是多少?(使用int函数取整,单位为%) 提示:在确定热带气旋中心点时,south_north 对应 Y 示 lat,west_east 对应 X 示 lon 思路: 如何得到500hPa高度上的相对湿度(垂直插值)? 怎样找到某点的空间位置/索引/格点位置/第几行第几列? 详细步骤 读取数据,取出slp、相对湿度数据; 将相对湿度在垂直方向上插值到指定等压面(500hPa); 定位热带气旋利奇马中心(海平面气压最低值); 利用利奇马中心的空间位置,求出该空间位置500hPa相对湿度。 友情提醒 np.where()函数:想到我了吗?!(在使用之前记得将Array格式切换为np.array()) 在确定热带气旋中心点时,south_north 对应 Y 示 lat,west_east 对应 X 示 lon 核心代码 print(np.where(np.array(ds_in.SLP==ds_in.SLP.min())==True) ) 写的代码: 本项目来源于和鲸社区,使用转载需要标注来源 作者: 剑吻鲸o28r 来源: https://www.heywhale.com/mw/project/6835da725479c3a76a796395 工作台 - Heywhale.com 工作台 - Heywhale.com import numpy as np from netCDF4 import Dataset from scipy.interpolate import PchipInterpolator # 1. 读取WRF文件 file_path = "/home/mw/input/typhoon9537/wrfout_d01_2019-08-09_06_00_00" wrf_file = Dataset(file_path, 'r') # 2. 获取海平面气压(PSFC)并找到最低气压中心位置 psfc = wrf_file.variables['PSFC'][0, :, :] # 取第一个时间步的海平面气压 min_psfc = np.min(psfc) y_idx, x_idx = np.where(psfc == min_psfc) center_y, center_x = y_idx[0], x_idx[0] # 气旋中心位置 # 3. 获取气压(P)和基础气压(PB)数据,计算全气压 P = wrf_file.variables['P'][0, :, :, :] # 取第一个时间步的扰动气压 PB = wrf_file.variables['PB'][0, :, :, :] # 取第一个时间步的基础气压 pressure = P + PB # 全气压 (Pa) # 4. 获取相对湿度(QVAPOR)并计算相对湿度 QVAPOR = wrf_file.variables['QVAPOR'][0, :, :, :] # 水汽混合比 (kg/kg) T = wrf_file.variables['T'][0, :, :, :] # 扰动位温 P_HYD = wrf_file.variables['P_HYD'][0, :, :, :] # 流体静力压,还需要补充代码并检查写的的代码是否正确
最新发布
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值