节前做好数据库内存排查

92 阅读2分钟

节前空间检查 1.表空间用量查询(使用有dba权限的用户登录plsql)

执行: select tablespace_name 表空间名, max_gb 最大可扩展大小, used_gb 已使用大小, round(100 * used_gb / decode(max_gb,0,1,max_gb)) 已使用率 from (select a.tablespace_name tablespace_name, round((a.bytes_alloc - nvl(b.bytes_free, 0)) / power(2, 30), 2) used_gb, round(a.maxbytes / power(2, 30), 2) max_gb from (select f.tablespace_name, sum(f.bytes) bytes_alloc, sum(decode(f.autoextensible, 'YES', f.maxbytes, 'NO', f.bytes)) maxbytes from dba_data_files f group by tablespace_name) a, (select f.tablespace_name, sum(f.bytes) bytes_free from dba_free_space f group by tablespace_name) b where a.tablespace_name = b.tablespace_name(+) union all select h.tablespace_name tablespace_name, round(sum(nvl(p.bytes_used, 0)) / power(2, 30), 2) used_gb, round(sum(decode(f.autoextensible, 'YES', f.maxbytes, 'NO', f.bytes)) / power(2, 30), 2) max_gb from vtempspaceheaderh,vtemp_space_header h, vtemp_extent_pool p, dba_temp_files f where p.file_id(+) = h.file_id and p.tablespace_name(+) = h.tablespace_name and f.file_id = h.file_id and f.tablespace_name = h.tablespace_name group by h.tablespace_name) order by 4 desc;

2.归档空间用量查询 2.1查询闪回空间占用率 执行: select t.file_type 文件类型,t.percent_space_used 闪回区已使用率 from v$flash_recovery_area_usage t where file_type='ARCHIVED LOG';

2.2查询集群共享磁盘信息 执行: SELECT NAME, trunc(TOTAL_MB/1024) 总大小_GB, trunc(FREE_MB/1024) 空闲大小_GB, trunc((TOTAL_MB - FREE_MB)/1024) 已使用大小_GB, TRUNC((TOTAL_MB - FREE_MB) / (DECODE(TOTAL_MB, 0, 1, TOTAL_MB)) * 100, 1) || '%' 已使用率 FROM V$ASM_DISKGROUP;

2.3使用服务器磁盘存放归档日志 3.附:加表空间步骤 3.1查看表空间使用情况 直接执行无需修改,建议: "已使用率"<80% 或者 "最大值(GB)"-"已使用(GB)"即"可扩展",大于100G select tablespace_name as "表空间名", max_gb as "最大值(GB)", used_gb as "已使用(GB)", round(100 * used_gb/decode(max_gb,0,1,max_gb)) as "已使用率" from (select a.tablespace_name tablespace_name, round((a.bytes_alloc - nvl(b.bytes_free, 0)) / power(2, 30), 2) used_gb, round(a.maxbytes / power(2, 30), 2) max_gb from (select f.tablespace_name, sum(f.bytes) bytes_alloc, sum(decode(f.autoextensible, 'YES', f.maxbytes, 'NO', f.bytes)) maxbytes from dba_data_files f group by tablespace_name) a, (select f.tablespace_name, sum(f.bytes) bytes_free from dba_free_space f group by tablespace_name) b where a.tablespace_name = b.tablespace_name(+) ) order by 4;

3.2查询数据文件存储策略 直接执行无需修改,若value为空则只需执行3.3.1部分,有值只需执行3.3.2部分: select name,value from v$parameter where name = 'db_create_file_dest';

3.3添加数据文件 3.3.1需指定路径版本

  1. 需修改"表空间名",查询表空间数据文件存放位置、使用情况: select * from dba_data_files t where t.tablespace_name='表空间名';

  2. 需修改"新建...位置",增加表空间数据文件,新文件不得与旧文件重名: alter tablespace 表空间名 add datafile '新建数据文件详细存放位置' size 100M AUTOEXTEND ON NEXT 100M MAXSIZE 16G;

3.3.2不需要指定路径版本 需修改"表空间名",增加表空间数据文件,无需手动编辑路径: alter tablespace 表空间名 add datafile size 100M AUTOEXTEND ON NEXT 100M MAXSIZE 16G;