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

部分利用oracle数据字典查询对应信息的语句。

查看当前用户的缺省表空间
 

SQL>select username,default_tablespace from user_users;

查看当前用户的角色

SQL>select * from user_role_privs;

查看当前用户的系统权限和表级权限

SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;

查看某表的大小

SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments
where segment_name=upper('&table_name');

查看表空间的名称及大小

select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;

查看回滚段名称及大小

select segment_name, tablespace_name, r.status, 
(initial_extent/1024) InitialExtent,(next_extent/1024) NextExtent, 
max_extents, v.curext CurExtent
From dba_rollback_segs r, v$rollstat v
Where r.segment_id = v.usn(+)
order by segment_name;

查看数据库的创建日期和归档方式

Select Created, Log_Mode, Log_Mode From V$Database;

捕捉运行很久的SQL

column username format a12 
column opname format a16 
column progress format a8

select username,sid,opname, 
      round(sofar*100 / totalwork,0) || '%' as progress, 
      time_remaining,sql_text 
from v$session_longops , v$sql 
where time_remaining <> 0 
and sql_address = address 
and sql_hash_value = hash_value 

查看数据表的参数信息

SELECT   partition_name, high_value, high_value_length, tablespace_name,
        pct_free, pct_used, ini_trans, max_trans, initial_extent,
        next_extent, min_extent, max_extent, pct_increase, FREELISTS,
        freelist_groups, LOGGING, BUFFER_POOL, num_rows, blocks,
        empty_blocks, avg_space, chain_cnt, avg_row_len, sample_size,
        last_analyzed
   FROM dba_tab_partitions
--WHERE table_name = :tname AND table_owner = :towner
ORDER BY partition_position

查找object为哪些进程所用

select 
p.spid,
s.sid,
s.serial# serial_num,
s.username user_name,
a.type object_type,
s.osuser os_user_name,
a.owner,
a.object object_name,
decode(sign(48 - command),
1,
to_char(command), 'Action Code #' || to_char(command) ) action,
p.program oracle_process,
s.terminal terminal,
s.program program,
s.status session_status   
from v$session s, v$access a, v$process p   
where s.paddr = p.addr and
     s.type = 'USER' and    
     a.sid = s.sid   and
a.object='SUBSCRIBER_ATTR'
order by s.username, s.osuser

回滚段查看

select rownum, sys.dba_rollback_segs.segment_name Name, v$rollstat.extents 
Extents, v$rollstat.rssize Size_in_Bytes, v$rollstat.xacts XActs, 
v$rollstat.gets Gets, v$rollstat.waits Waits, v$rollstat.writes Writes, 
sys.dba_rollback_segs.status status from v$rollstat, sys.dba_rollback_segs, 
v$rollname where v$rollname.name(+) = sys.dba_rollback_segs.segment_name and 
v$rollstat.usn (+) = v$rollname.usn order by rownum

耗资源的进程

select s.schemaname schema_name,    decode(sign(48 - command), 1, 
to_char(command), 'Action Code #' || to_char(command) ) action,    status 
session_status,   s.osuser os_user_name,   s.sid,         p.spid ,         s.serial# serial_num,   
nvl(s.username, '[Oracle process]') user_name,   s.terminal terminal,    
s.program program,   st.value criteria_value from v$sesstat st,   v$session s , v$process p   
where st.sid = s.sid and   st.statistic# = to_number('38') and   ('ALL' = 'ALL' 
or s.status = 'ALL') and p.addr = s.paddr order by st.value desc, p.spid asc, s.username asc, s.osuser asc

查看锁(lock)情况

select /*+ RULE */ ls.osuser os_user_name,   ls.username user_name,   
decode(ls.type, 'RW', 'Row wait enqueue lock', 'TM', 'DML enqueue lock', 'TX', 
'Transaction enqueue lock', 'UL', 'User supplied lock') lock_type,   
o.object_name object,   decode(ls.lmode, 1, null, 2, 'Row Share', 3, 
'Row Exclusive', 4, 'Share', 5, 'Share Row Exclusive', 6, 'Exclusive', null) 
lock_mode,    o.owner,   ls.sid,   ls.serial# serial_num,   ls.id1,   ls.id2    
from sys.dba_objects o, (   select s.osuser,    s.username,    l.type,     
l.lmode,    s.sid,    s.serial#,    l.id1,    l.id2   from v$session s,     
v$lock l   where s.sid = l.sid ) ls where o.object_id = ls.id1 and    o.owner 
<> 'SYS'   order by o.owner, o.object_name

查看等待(wait)情况

SELECT v$waitstat.class, v$waitstat.count count, SUM(v$sysstat.value) sum_value 
FROM v$waitstat, v$sysstat WHERE v$sysstat.name IN ('db block gets', 
'consistent gets') group by v$waitstat.class, v$waitstat.count

查询表空间使用情况

select a.tablespace_name "表空间名称",
100-round((nvl(b.bytes_free,0)/a.bytes_alloc)*100,2) "占用率(%)",
round(a.bytes_alloc/1024/1024,2) "容量(M)",
round(nvl(b.bytes_free,0)/1024/1024,2) "空闲(M)",
round((a.bytes_alloc-nvl(b.bytes_free,0))/1024/1024,2) "使用(M)",
Largest "最大扩展段(M)",
to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') "采样时间" 
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,
(select round(max(ff.length)*16/1024,2) Largest,
   ts.name tablespace_name 
from sys.fet$ ff, sys.file$ tf,sys.ts$ ts 
where ts.ts#=ff.ts# and ff.file#=tf.relfile# and ts.ts#=tf.ts# 
group by ts.name, tf.blocks) c 
where a.tablespace_name = b.tablespace_name and a.tablespace_name = c.tablespace_name


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

相关文章:

  • 近几年新笔记本重装系统方法及一些注意事项
  • 【时间之外】IT人求职和创业应知【37】-AIGC私有化
  • sapiens推理的安装与使用
  • .NET桌面应用架构Demo与实战|WPF+MVVM+EFCore+IOC+DI+Code First+AutoMapper
  • 在 Windows 11 中使用 MuMu 模拟器 12 国际版配置代理
  • Ansible内置模块之known_hosts
  • 基于Python的招聘信息推荐系统
  • 力扣(leetcode)面试经典150题——27. 移除元素
  • gitlab容器的迁移(部署)并配置自动备份
  • [webgis 0基础到找工作]------JavaScript--DOM 注册事件 day09
  • vue实现展示并下载后端返回的图片流
  • uniapp 修改网页标题title
  • 【新人系列】Python 入门(十一):控制结构
  • ODC 如何精确呈现SQL耗时 | OceanBase 开发者工具解析
  • halcon3D gen_image_to_world_plane_map的图像高精度拼接技术
  • 计算机网络-MSTP基础实验一(单域多实例)
  • HTML、CSS与JavaScript基础
  • 云原生周刊:Kubernetes v1.32 要来了
  • golang开源框架:go开源验证框架validator
  • leetcode 面试150之 Z 字形变换
  • Solana应用开发常见技术栈
  • 高效服务器管理新选择:CasaOS轻NAS系统部署1Panel面板并实现远程访问
  • 如何用Excel批量提取文件夹内所有文件名?两种简单方法推荐
  • sql专场练习(二)(11-15)
  • Springboot之登录模块探索(含Token,验证码,网络安全等知识)
  • 微信小程序组件之swiper介绍