当前位置: 首页 > article >正文

ORACLE之DBA常用数据库查询

  1. 数据库信息
    1. 数据库概要

select a.name "DB Name",

       e.global_name "Global Name",

       c.host_name "Host Name",

       c.instance_name "Instance Name" ,

       DECODE(c.logins,'RESTRICTED','YES','NO') "Restricted Mode",

       a.log_mode  "Archive Log Mode"

FROM v$database a, v$version b, v$instance c,global_name e

WHERE b.banner LIKE '%Oracle%';

    1. 参数文件(spfile还是pfile)

select nvl(value,'pfile') "Parameter_File"

from v$parameter where Name='spfile';

    1. 非默认的参数

select name, rtrim(value) "pvalue"

from v$parameter

where isdefault = 'FALSE'

order by name;

    1. 控制文件及其状态

select Name,Status from v$controlfile;

    1. 数据库版本信息

select * from v$version;

    1. 数据库组件(true:已安装,false:未安装)

SELECT PARAMETER, VALUE FROM V$OPTION;

    1. 实例信息

select instance_name,host_name,version,status,database_status from v$instance;

    1. NLS参数设置

SELECT * FROM NLS_Database_Parameters;

    1. 已装载的产品选项

select COMP_ID, COMP_NAME, VERSION,STATUS from dba_registry;

    1. 数据库的并发数

select count(*) as "并发数" from v$session where status='ACTIVE';

    1. 数据库Session连接数

select count(*) as "连接数" from v$session;

    1. 数据库总大小(GB)

select round(sum(space)) "总容量/Gb"

  from (select sum(bytes) / 1024 / 1024 / 1024 space

          from dba_data_files

        union all

        select nvl(sum(bytes) / 1024 / 1024 / 1024, 0) space

          from dba_temp_files

        union all

        select sum(bytes) / 1024 / 1024 / 1024 space from v$log);

    1. 数据库服务器运行的操作系统

select PLATFORM_NAME from v$database;

    1. DBID

select dbid from v$database;

    1. Flashback是否启动

select decode(flashback_on,'NO','未启用','启用') as "闪回模式" from v$database;

  1. 存储结构、表空间、数据文件
    1. 表空间及数据文件

select tablespace_name,file_name,

bytes/1024/1024 "Total Size(MB)",autoExtensible "Auto"

from dba_data_files

order by tablespace_name,file_id;

    1. 表空间状态及其大小使用情况

SELECT  d.tablespace_name "Name", d.status "Status", d.contents "Type",

        ROUND(NVL(a.bytes / 1024 / 1024, 0), 2) "Size (MB)",

        ROUND(NVL(a.bytes - NVL(f.bytes, 0), 0) / 1024 /1024, 2) "Used (MB)",

        ROUND(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0), 2) "Used%",

        ROUND(NVL(a.maxbytes / 1024 / 1024, 0), 2) "Max Size (MB)",

        DECODE(NVL(a.maxbytes,0), 0, 0, ROUND(NVL(a.maxbytes - a.bytes, 0) / 1024 / 1024, 2)) "Unused (MB)",

        DECODE(NVL(a.maxbytes,0), 0, 0, ROUND((1 - NVL(a.bytes / a.maxbytes, 0))*100, 2)) "Unused%"

  FROM sys.dba_tablespaces d,

      (SELECT tablespace_name, SUM(bytes) bytes, SUM(maxbytes) maxbytes

         FROM dba_data_files GROUP BY tablespace_name

       UNION ALL

       SELECT tablespace_name, SUM(bytes) bytes, SUM(maxbytes) maxbytes

         FROM dba_temp_files GROUP BY tablespace_name) a,

      (SELECT tablespace_name, SUM(bytes) bytes

         FROM dba_free_space GROUP BY tablespace_name

       UNION ALL

       SELECT tablespace_name, SUM(bytes_free) bytes

         FROM gv$temp_space_header GROUP BY tablespace_name) f

 WHERE d.tablespace_name = a.tablespace_name(+)

      AND d.tablespace_name = f.tablespace_name(+);

    1. 数据文件状态及其大小使用情况

SELECT  a.tablespace_name "TableSpace Name", a.File_Name "File Name",

        a.status "Status", a.AutoExtensible "Auto",

        round(NVL(a.bytes / 1024 / 1024, 0),1) "Size (MB)",

        round(NVL(a.bytes - NVL(f.bytes, 0),0)/1024/1024, 1) "Used (MB)",

        round(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0), 2) "Used %"

FROM dba_data_files a,

  (select file_id, sum(bytes) bytes

   from dba_free_space group by File_id) f

WHERE a.file_id=f.file_id(+)

order by a.tablespace_name,a.File_id;

    1. 不使用临时文件的临时表空间

select tablespace_name,contents from dba_tablespaces

where contents='TEMPORARY' and tablespace_name not in

  (select tablespace_name from dba_temp_files);

    1. 无效的数据文件(offline)

select f.tablespace_name,f.file_name,d.status

from dba_data_files f,v$datafile d

where d.status='OFFLINE' and f.file_id=File#(+);

    1. 处于恢复模式的文件

select f.tablespace_name,f.file_name

from dba_data_files f, v$recover_file r

where f.file_id=r.file#;

    1. 含有50个以上的Extent30%以上碎片的表空间

select s.tablespace_name,

       round(100 * f.hole_count / (f.hole_count + s.seg_count)) pct_fragmented,

       s.seg_count segments, f.hole_count holes

from  (Select tablespace_name, count(*) seg_count

       from   dba_segments group by tablespace_name) s,

      (Select   tablespace_name, count(*) hole_count

       from     dba_free_space  group by tablespace_name) f

where s.tablespace_name = f.tablespace_name

      and s.tablespace_name in (Select tablespace_name

           from dba_tablespaces where contents = 'PERMANENT')

             And s.tablespace_name not in ('SYSTEM')

      and 100 * f.hole_count / (f.hole_count + s.seg_count) > 30

      and s.seg_count > 50;

    1. 表空间上的I/O分布

SELECT  t.name   ts_name,

        f.name  file_name,

        s.phyrds phy_reads,

        s.phyblkrd phy_blockreads,

        s.phywrts phy_writes,

        s.phyblkwrt phy_blockwrites

FROM    gv$tablespace t,

        gv$datafile f,

        gv$filestat s

WHERE   t.ts# = f.ts#

        and

        f.file# = s.file#

ORDER BY s.phyrds desc, s.phywrts desc;

    1. 数据文件上的I/O分布

Select   ts.NAME "Table Space", D.NAME "File Name",

         FS.PHYRDS "Phys Rds",

         decode(fstot.sum_ph_rds,  0, 0,

                 round(100 * FS.PHYRDS    / fstot.sum_ph_rds,  2)) "% Phys Rds",

         FS.PHYWRTS "Phys Wrts",

         decode(fstot.sum_ph_wrts, 0, 0,

                 round(100 * FS.PHYWRTS   / fstot.sum_ph_wrts, 2)) "% Phys Wrts"

FROM   V$FILESTAT FS, V$DATAFILE d, V$tablespace ts,

      (select sum(phyrds)   sum_ph_rds, sum(phywrts)   sum_ph_wrts,

              sum(phyblkrd) sum_bl_rds, sum(phyblkwrt) sum_bl_wrts

       from   V$filestat) fstot

WHERE  D.FILE# = FS.FILE# AND D.TS#   = TS.TS#;

    1. Next Extent 相对于段当前已分配字节过大(>=2)或过小(<10%)Segments

Select InitCap(SEGMENT_TYPE) "Type", OWNER, SEGMENT_NAME, BYTES, NEXT_EXTENT,

       ROUND(100 * NEXT_EXTENT / BYTES) "Percent(Next/Bytes)"

FROM   DBA_SEGMENTS

WHERE  ((ROUND(100 * NEXT_EXTENT / BYTES) < 10) OR

     (ROUND(100 * NEXT_EXTENT / BYTES) >= 200))

  AND    SEGMENT_TYPE NOT IN ('ROLLBACK', 'TEMPORARY', 'CACHE', 'TYPE2 UNDO')

order by 2,3,1;


    http://www.kler.cn/a/415449.html

    相关文章:

  1. SpringBoot小知识(2):日志
  2. spark3.x之后时间格式数据偶发报错org.apache.spark.SparkUpgradeException
  3. flink中barrier不对齐的原因和影响
  4. 简单好用的折线图绘制!
  5. 【Android+多线程】IntentService 知识总结:应用场景 / 使用步骤 / 源码分析
  6. [SWPUCTF 2021 新生赛]include
  7. openGauss你计算的表大小,有包含toast表么?
  8. ArcGIS pro中的回归分析浅析(加更)关于广义线性回归工具的补充内容
  9. 2.安装docker、docker compose
  10. 使用Native AOT发布C# dll 提供给C++调用
  11. c++趣味编程玩转物联网:树莓派Pico控制 LED点阵屏
  12. 11.25.2024刷华为OD
  13. 【动态规划】完全背包问题应用
  14. 淘宝Vision Pro:革新购物体验的沉浸式未来
  15. QML 之 画布元素学习
  16. 51单片机从入门到精通:理论与实践指南常用资源篇(五)
  17. 提升数据分析效率:Excel Power Query和Power Pivot的妙用
  18. 获取字 short WORD 上指定的位是否有效
  19. Stability AI最新一代图像生成模型stable-diffusion-3.5-large分享
  20. 力扣题库Day4(持续更新中...)
  21. AutoGLM的一小步,人机交互进化的一大步
  22. 查看k8s集群中pod和node的资源使用情况
  23. 基于stm32单片机的教室节能系统设计
  24. C# 集合(Collection)
  25. 从Facebook的技术演进看社交媒体的未来趋势
  26. 【微服务】http客户端Feign