码迷,mamicode.com
首页 > 数据库 > 详细

Oracle常用命令

时间:2018-02-13 15:40:45      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:div   回滚   变量   size   hrp   member   where   control   表空间   

Oracle常用命令

  • 查询oracle版本

select * from v$version;
  • 比较命令decode

select decode(sign(变量1 - 变量2), -1, 变量1, 变量2) from dual; --取较小值
  • 查看表大小

select segment_name,
       tablespace_name,
       bytes B,
       bytes / 1024 KB,
       bytes / 1024 / 1024 MB
  from user_segments
 where segment_type = TABLE;
  • 查看死锁与解锁

  查询死锁:

SELECT l.session_id sid,
       s.serial#,
       l.locked_mode,
       l.oracle_username,
       l.os_user_name,
       s.machine,
       s.terminal,
       o.object_name,
       s.logon_time
  FROM v$locked_object l, all_objects o, v$session s
 WHERE l.object_id = o.object_id
   AND l.session_id = s.sid
 ORDER BY sid, s.serial#;

  解锁:

alter system kill session sid,serial#; --结合上面查询死锁结果使用
  • 查询数据库正在使用用户信息

select a."MACHINE", a."PROGRAM", a."PREV_EXEC_START", a.terminal
  from v$session a
 where a.username = HRPDEV;
  • 查看表空间名称及大小

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 tablespace_name,
       file_id,
       file_name,
       round(bytes / (1024 * 1024), 0) total_space
  from dba_data_files
 order by 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 name from v$controlfile; 
  • 查看日志文件

select member from v$logfile; 
  • 查看表空间的使用情况

select sum(bytes) / (1024 * 1024) as free_space, tablespace_name
  from dba_free_space
 group by tablespace_name;

select a.tablespace_name,
       a.bytes total,
       b.bytes used,
       c.bytes free,
       (b.bytes * 100) / a.bytes "% USED ",
       (c.bytes * 100) / a.bytes "% FREE "
  from sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
 where a.tablespace_name = b.tablespace_name
   and a.tablespace_name = c.tablespace_name;
  • 查看数据库对象

select owner, object_type, status, count(*) count#
  from all_objects
 group by owner, object_type, status;

 

Oracle常用命令

标签:div   回滚   变量   size   hrp   member   where   control   表空间   

原文地址:https://www.cnblogs.com/BillyYoung/p/8446595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!