运维联盟俱乐部

 找回密码
 立即注册
查看: 1658|回复: 0

[日常管理] em上查询数据库基本信息

[复制链接]
  • TA的每日心情
    开心
    2023-8-9 11:05
  • 发表于 2020-5-30 07:31:15 | 显示全部楼层 |阅读模式
    em上管理得数据库多了以后,有时候需要查询所有数据库得特定信息,这是可以对em管理库进行自定义得查询来满足不同得需求

    1. --查询platform平台数量分布
    2. select PLATFORM_NAME, count(*)
    3.   from db_database
    4. group by PLATFORM_NAME
    5. order by PLATFORM_NAME

    6. --查询os平台的数量
    7. select os,count(*) from dblist group by os order by 2 desc

    8. --查询version的数量
    9. select os,count(*) from dblist group by os order by 2 desc

    10. --查询没有开启归档的数据库
    11. select d.dbname, a.app, a.mip, d.log_mode
    12.   from db_database d, dblist a
    13. where d.dbname = a.dblink
    14.    and d.log_mode = 'NOARCHIVELOG'


    15. --查询只有1个控制文件的数据库
    16. select dbname, count(*)
    17.   from db_controlfile
    18. group by dbname
    19. having count(*) < 2;

    20. --查询按年份创建的数据库
    21. select substr(to_char(created, 'yyyymmdd'), 1, 4) c_year, count(*)
    22.   from db_database
    23. group by substr(to_char(created, 'yyyymmdd'), 1, 4)
    24. order by substr(to_char(created, 'yyyymmdd'), 1, 4)

    25. --查询具有dba权限的用户
    26. break on dbname on app on mip
    27. select r.dbname, d.app, d.mip, r.grantee user_with_dba
    28.   from db_role r, dblist d
    29. where d.dblink(+) = r.dbname
    30.    and r.granted_role = 'DBA'
    31.    and r.grantee not in ('SYS',
    32.                          'SYSTEM',
    33.                          'SYSMAN',
    34.                          'GOLDENGATE',
    35.                          'OGG',
    36.                          'OGGUSER',
    37.                          'DIRECTOR')
    38. order by 2

    39. --查询具有dba权限的用户的历史情况,按数据库,按月份排序
    40. select dbname, to_char(time, 'yyyy-mm-dd') time, count(*)
    41.   from hist_role
    42. where granted_role = 'DBA'
    43. group by dbname, to_char(time, 'yyyy-mm-dd')
    44. order by 1, 2;

    45. --查询运行超过1年的数据库
    46. select l.dbname, d.app, d.mip, l.instance_name, l.uptime "DAYS"
    47.   from dblist d, db_instance l
    48. where d.dblink = l.dbname
    49.    and l.uptime > 365
    50. order by l.instance_name, l.uptime desc

    51. --查询asm_diskgroup可用空间
    52. select a.dbname,
    53.        d.app,
    54.        a.group_number,
    55.        a.name,
    56.        a.total_mb,
    57.        a.free_mb,
    58.        round(NVL(a.free_mb / a.total_mb * 100, 0), 0) pct_free
    59.   from dblist d, db_asmdg a
    60. where d.dblink = a.dbname
    61.    and round(NVL(a.free_mb / a.total_mb * 100, 0), 0) < '&pct_value'
    62. order by pct_free

    63. --查询不可用对象
    64. select t.dbname, d.app, t.owner, t.object_type, count(object_name) count
    65.   from dblist d, db_object t
    66. where d.dblink = t.dbname
    67. group by t.dbname, d.app, t.owner, t.object_type
    68. order by t.dbname, t.owner

    69. --查询特定值的parameter
    70. select p.dbname, d.app, d.mip, p.pname, p.value
    71.   from dblist d, db_parameter p
    72. where d.dblink = p.dbname
    73.    and p.pname = '&pname'

    74. --查询实例会话数量

    75. select s.dbname, d.app, d.mip, s.inst_id, count(*) session_count
    76.   from dblist d, db_session s
    77. where d.dblink = s.dbname
    78.    and d.jiagou = 'RAC'
    79. group by s.dbname, d.app, d.mip, s.inst_id
    80. order by 1, 2, 3


    81. --查询数据文件位置
    82. select dbname,
    83.        count(distinct(substr(file_name, 0, 1))) file_type
    84.   from db_datafile
    85. group by dbname
    86. having count(distinct(substr(file_name, 0, 1))) > 1
    87. order by file_type desc

    88. --查询数据库的数据量
    89. select dbname,
    90.        round(sum(total_mb) / 1024, 0) total_gb,
    91.        round(sum(used_mb) / 1024, 0) used_gb
    92.   from db_datafile
    93. group by dbname
    94. order by total_gb desc

    95. --查询需要扩容的表空间
    96. select dbname, name, ts_size, free, pct_free
    97.   from db_tablespace
    98. where type = 'PERMANENT'
    99.    and pct_free < 15
    100.    and free < 10000
    101. order by 1, 2, 5

    102. --查询特定表空间的使用量
    103. select dbname, name, ts_size, free, pct_free
    104.   from db_tablespace
    105. where type = 'PERMANENT'
    106.    and name = '&TS_name'
    107. order by 3 desc

    108. --查询1月内创建的用户
    109. select u.dbname, d.app, u.username, u.created, u.default_tablespace, u.profile
    110.   from db_user u, dblist d
    111. where u.dbname = d.dblink
    112.    and u.account_status = 'OPEN'
    113.    and u.created > sysdate - 30

    114. --查询test账户
    115. select u.dbname, d.app, d.mip, u.username, u.account_status
    116.   from db_user u, dblist d
    117. where u.dbname = d.dblink
    118.    and u.username like '%TEST%'
    119. order by 5
    复制代码




    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    运维联盟俱乐部 ( 冀ICP备19036648号 )

    GMT+8, 2024-5-17 14:42 , Processed in 0.046137 second(s), 21 queries , Gzip On.

    Powered by Discuz! X3.4

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表