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

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

sql 复制代码
SQL>select username,default_tablespace from user_users;

查看当前用户的角色

sql 复制代码
SQL>select * from user_role_privs;

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

sql 复制代码
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;

查看某表的大小

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

查看表空间的名称及大小

sql 复制代码
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;

查看回滚段名称及大小

sql 复制代码
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;

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

sql 复制代码
Select Created, Log_Mode, Log_Mode From V$Database;

捕捉运行很久的SQL

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 

查看数据表的参数信息

sql 复制代码
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为哪些进程所用

sql 复制代码
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

回滚段查看

sql 复制代码
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

耗资源的进程

sql 复制代码
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)情况

sql 复制代码
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)情况

sql 复制代码
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

查询表空间使用情况

sql 复制代码
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
相关推荐
2402_8575834914 分钟前
Spring Boot框架:电商开发的新趋势
数据库·spring boot·后端
打码人的日常分享16 分钟前
【资料】网络安全风险评估报告,风险管理报告,网络安全风险管理计划,网络安全网络安全能力验证报(Word原件)
数据库·安全·web安全·需求分析·规格说明书
煎饼小狗37 分钟前
Redis五大基本类型——List列表命令详解(命令用法详解+思维导图详解)
数据结构·数据库·经验分享·redis·缓存·list
gjh12081 小时前
MySQL存储引擎InnoDB 和MyISAM的区别和使用
数据库·mysql
DashVector1 小时前
如何使用DashVector的多向量检索
开发语言·数据库·人工智能·数据库架构
LanFengXuXue2 小时前
Clickhouse集群新建用户、授权以及remote权限问题
数据库·clickhouse
好记忆不如烂笔头abc2 小时前
ORA-00257: archiver error
数据库·oracle
GOTXX2 小时前
【MySQL】MySQL数据库入门:构建你的数据基石
linux·数据库·mysql·开发工具·基础
祁思妙想2 小时前
28.<Spring博客系统④(使用MD5摘要算法对数据库密码进行加密)>
java·数据库·spring
shix .3 小时前
django框架-settings.py文件的配置说明
数据库·django·sqlite