对于数据库中表空间查看,想必大家都有很多的脚本已经在用了,自己也啰嗦一下,分享一个通过shell脚本查看表空间使用情况的例子。

脚本如下:

sqlplus -s $DB_CONN_STR@$SH_DB_SID  <

set echo off heading on underline on;

column inst_num  heading "Inst Num"  new_value inst_num  format 99999;

column inst_name heading "Instance"  new_value inst_name format a12;

column db_name  heading "DB Name"  new_value db_name  format a12;

column dbid      heading "DB Id"    new_value dbid      format 9999999999 just c;

prompt

prompt Current Instance

prompt ~~~~~~~~~~~~~~~~

select d.dbid            dbid

, d.name            db_name

, i.instance_number inst_num

, i.instance_name  inst_name

from v\$database d,

v\$instance i;

set term on feedback off lines 130 pagesize 999 tab off trims on

column MB format 999,999,999  heading "Total MB"

column free format 9,999,999 heading "Free MB"

column used format 99,999,999 heading "Used MB"

column Largest format 999,999 heading "LrgstMB"

column tablespace_name format a20 heading "Tablespace"

column status format a3 truncated

column max_extents format 99999999999 heading "MaxExt"

col extent_management          for a1 trunc  head "M"

col allocation_type            for a1 trunc  head "A"

col Ext_Size for a4 trunc head "Init"

column pfree format a3 trunc heading "%Fr"

break on report

compute sum of MB on report

compute sum of free on report

compute sum of used on report

select

d.tablespace_name,

decode(d.status,

'ONLINE', 'OLN',

'READ ONLY', 'R/O',

d.status) status,

d.extent_management,

decode(d.allocation_type,

'USER','',

d.allocation_type) allocation_type,

(case

when initial_extent < 1048576

then lpad(round(initial_extent/1024,0),3)||'K'

else lpad(round(initial_extent/1024/1024,0),3)||'M'

end) Ext_Size,

NVL (a.bytes / 1024 / 1024, 0) MB,

NVL (f.bytes / 1024 / 1024, 0) free,

(NVL (a.bytes / 1024 / 1024, 0) - NVL (f.bytes / 1024 / 1024, 0)) used,

NVL (l.large / 1024 / 1024, 0) largest,

d.MAX_EXTENTS ,

lpad(round((f.bytes/a.bytes)*100,0),3) pfree,

(case when round(f.bytes/a.bytes*100,0) >= 20 then ' ' else '*' end) alrt

FROM sys.dba_tablespaces d,

(SELECT  tablespace_name, SUM(bytes) bytes

FROM dba_data_files

GROUP BY tablespace_name) a,

(SELECT  tablespace_name, SUM(bytes) bytes

FROM dba_free_space

GROUP BY tablespace_name) f,

(SELECT  tablespace_name, MAX(bytes) large

FROM dba_free_space

GROUP BY tablespace_name) l

WHERE d.tablespace_name = a.tablespace_name(+)

AND d.tablespace_name = f.tablespace_name(+)

AND d.tablespace_name = l.tablespace_name(+)

AND NOT (d.extent_management LIKE 'LOCAL' AND d.contents LIKE 'TEMPORARY')

UNION ALL

select

d.tablespace_name,

decode(d.status,

'ONLINE', 'OLN',

'READ ONLY', 'R/O',

d.status) status,

d.extent_management,

decode(d.allocation_type,

'UNIFORM','U',

'SYSTEM','A',

'USER','',

d.allocation_type) allocation_type,

(case

when initial_extent < 1048576

then lpad(round(initial_extent/1024,0),3)||'K'

else lpad(round(initial_extent/1024/1024,0),3)||'M'

end) Ext_Size,

NVL (a.bytes / 1024 / 1024, 0) MB,

(NVL (a.bytes / 1024 / 1024, 0) - NVL (t.bytes / 1024 / 1024, 0)) free,

NVL (t.bytes / 1024 / 1024, 0) used,

NVL (l.large / 1024 / 1024, 0) largest,

d.MAX_EXTENTS ,

lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3) pfree,

(case when nvl(round(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,0),100) >= 20 then ' ' else '*' end) alrt

FROM sys.dba_tablespaces d,

(SELECT  tablespace_name, SUM(bytes) bytes

FROM dba_temp_files

GROUP BY tablespace_name order by tablespace_name) a,

(SELECT  tablespace_name, SUM(bytes_used  ) bytes

FROM v\$temp_extent_pool

GROUP BY tablespace_name) t,

(SELECT  tablespace_name, MAX(bytes_cached) large

FROM v\$temp_extent_pool

GROUP BY tablespace_name order by tablespace_name) l

WHERE d.tablespace_name = a.tablespace_name(+)

AND d.tablespace_name = t.tablespace_name(+)

AND d.tablespace_name = l.tablespace_name(+)

AND d.extent_management LIKE 'LOCAL'

AND d.contents LIKE 'TEMPORARY'

ORDER by 1

/

prompt

exit

EOF

运行结果相对比较简单,也很清晰。

linux查询表空间脚本,通过Shell脚本查看数据库表空间使用情况相关推荐

  1. linux查看mysql表空间使用率_Oracle查看数据库表空间使用情况sql语句

    Oracle查看数据库表空间使用情况sql语句 SELECT UPPER(F.TABLESPACE_NAME)        "表空间名", D.TOT_GROOTTE_MB    ...

  2. mysql查看数据库表空间占用情况

    查看数据库test的各个表的空间占用情况 select table_schema as '数据库', table_name as '表名', table_rows as '记录数', truncate ...

  3. oracle数据库扩大表空间,[小技巧]手工扩大Oracle数据库表空间的方法

    1.首先查看表空间的名字和所属文件select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_spacefr ...

  4. 查看数据库表空间.md

    查看数据占用空间大小: SELECT CONCAT(ROUND(SUM(data_length)/(1024*1024*1024), 6), ' GB') AS 'Total Data Size' F ...

  5. linux mysql 写shell_Linux—编写shell脚本操作数据库执行sql

    修改数据库数据 在升级应用时,我们常常会遇到升级数据库的问题,这就涉及到sql脚本的编写. 一般我们会通过写sql脚本,然后将xxx.sql脚本放到数据库中进行source xxx.sql执行.本篇文 ...

  6. Linux系统一键安全加固shell脚本编写思路

    本次分享一下个人在对Linux系统一键安全加固shell脚本编写时的一些思路: Linux系统一键安全加固shell脚本编写思路 1.编写须知 1.1 脚本使用说明 1.2 主要功能说明: 1.3隐藏 ...

  7. 嵌入式 Linux 入门(五、Shell 脚本编程上:认识 Shell 脚本)

    大家好,是矜辰所致,嵌入式 Linux入 门第五课,本课开始简单学习一下 Shell 脚本编程. 目录 前言 一.Shell 脚本基础说明 1.1 什么是 Shell 脚本 1.2 Shell 脚本的 ...

  8. LINUX下的流量监控shell脚本

    这篇文章主要介绍了LINUX下的流量监控shell脚本,可以适用任何Linux版本,需要的朋友可以参考下 一.脚本源码 # vi /etc/rc.d/traffic_monitor.sh ------ ...

  9. linux cc脚本,Linux运维知识之Linux简单处理CC攻击shell脚本

    本文主要向大家介绍了Linux运维知识之Linux简单处理CC攻击shell脚本,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助. 第一个脚本是通过查找日志中访问次数过多的ip,并 ...

最新文章

  1. 大型对冲基金正训练AI交易 5年后AI在量化中将成主流
  2. Qt Creator指定环境设置
  3. 详解C#break ,continue, return
  4. DataTable操作
  5. pcb二次钻孔_作为一名合格的PCB设计工程师,了解生产制造很重要
  6. opencv 图像仿射变换 计算仿射变换后对应特征点的新坐标 图像旋转、缩放、平移...
  7. vue字符串转时间_vue总结01
  8. nRF52832 矩阵按键调试 同一列上的按键 任意两个按键 按下 检测不到低电平(电平拉不下来)...
  9. 实战HTML:静态登录界面
  10. java生成 动态 pdf_java根据模板HTML动态生成PDF
  11. 第3章 Kafka API
  12. 夜神模拟器和虚拟机(docker) 在windows上设置不兼容
  13. OBS(Open Broadcaster Software)桌面视频直播软件/直播推流工具使用方法指南
  14. la是什么牌子_la bruket是什么牌子_哪个国家的_什么档次
  15. 桌面图标全部成被选中状态解决办法
  16. 自制IDEAWebStorm主题,轻仿VsCode-One Dark Pro
  17. 深度学习系列37:CLIP模型
  18. 2020年自动驾驶汽车V2V解决方案-设计需求挖掘
  19. 1074:津津的储蓄计划
  20. 计算机二级刷题先EXCEL,备考篇丨迎接计算机二级考试

热门文章

  1. python正则表达式模块_Python正则表达式模块re
  2. 有关计算机编程论文,有关计算机程序的论文范文
  3. python实现api server,初学python,准备学习做个restful api server,现在有些困惑
  4. python3解码base64_python3base64解码混乱的换行符
  5. python一个函数可以有参数也可以没有参数_Python:有和没有关键字参数的lambda函数行为?...
  6. Mac笔记本Postman升级为新版本后,打开时一直转圈,无法使用
  7. Python终端输出中文
  8. Git1天打卡 day13-查看仓库文件改动状态
  9. 21天Jmeter打卡Day18 前置处理器_熟悉常用组件
  10. 做了5年测试连一门语言都没学?逆袭后拿到3个超22K offer!