Oracle DBA常用查询

–1. 查询系统所有对象
select owner, object_name, object_type, created, last_ddl_time, timestamp, status
from dba_objects
where owner=upper('scott')

–2. 查看系统所有表
select owner, table_name, tablespace_name from dba_tables

–3. 查看所有用户的表
select owner, table_name, tablespace_name from all_tables

–4. 查看当前用户表
select table_name, tablespace_name from user_tables

–5. 查看用户表索引
select t.*,i.index_type from user_ind_columns t, user_indexes i where
t.index_name = i.index_name and t.table_name = i.table_name
and t.table_name = 要查询的表

–6. 查看主键
select cu.* from user_cons_columns cu, user_constraints au
where cu.constraint_name = au.constraint_name
and au.constraint_type = upper('p') and au.table_name = 要查询的表

–7. 查看唯一性约束
select column_name from user_cons_columns cu, user_constraints au
where cu.constraint_name = au.constraint_name and au.constraint_type =  upper('u')
and au.table_name = 要查询的表

–8. 查看外键
select * from user_constraints c where c.constraint_type = 'r' and c.table_name = 要查询的表
select * from user_cons_columns cl where cl.constraint_name = 外键名称
select * from user_cons_columns cl where cl.constraint_name = 外键引用表的键名

–9. 查看表的列属性
select t.*,c.comments
from user_tab_columns t, user_col_comments c
where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = 要查询的表

–10. 查看所有表空间
select tablespace_name from dba_data_files group by tablespace_name

############################################
–1. 查看oracle最大连接数
sql>show parameter processes    #最大连接数

–2. 修改最大连接数
sql>alter system set processes=value scope=spfile
–重启数据库
sql>shutdown force
sql>start force

–3. 查看当前连接数
sql>select * from v$session where username is not null

–4. 查看不同用户的连接数
sql>select username,count(username) from v$session where username is not null group by username #查看指定用户的连接数

–5. 查看活动的连接数
sql>select count(*) from v$session where status='active' #查看并发连接数

–6. 查看指定程序的连接数
sql>select count(*) from v$session where program='jdbc thin client' #查看jdbc连接oracle的数目

–7. 强行断开用户连接的方法
sql>select sid,serial# from v$session where username='ERP';(注意:serial# 中的 # 不能漏掉)

sql>alter system kill session 'sid,serial';(select 可能会返回多条记录,所以alter也要执行多次!)

–7. 查看数据库安装实例(dba权限)
sql>select * from v$instance

–8. 查看运行实例名
sql>show parameter instance_name

–9. 查看数据库名
sql>show parameter db_name

–10. 查看数据库域名
sql>show parameter db_domain

–11. 查看数据库服务名
sql>show parameter service_names

–12. 查看全局数据库名
sql>show parameter global

–13. 查看表空间使用率

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
-- (1)
select dbf.tablespace_name,
       dbf.totalspace "总量(m)",
       dbf.totalblocks as "总块数",
       dfs.freespace "剩余总量(m)",
       dfs.freeblocks "剩余块数",
       (dfs.freespace / dbf.totalspace) * 100 as "空闲比例"
  from (select t.tablespace_name,
               sum(t.bytes) / 1024 / 1024 totalspace,
               sum(t.blocks) totalblocks
          from dba_data_files t
         group by t.tablespace_name) dbf,
       (select tt.tablespace_name,
               sum(tt.bytes) / 1024 / 1024 freespace,
               sum(tt.blocks) freeblocks
          from dba_free_space tt
         group by tt.tablespace_name) dfs
 where trim(dbf.tablespace_name) = trim(dfs.tablespace_name)
-- (2)
select t.name "tablespace name",
       free_space,
       (total_space - free_space) used_space,
       total_space
  from (select tablespace_name, sum(bytes / 1024 / 1024) free_space
          from sys.dba_free_space
         group by tablespace_name) free,
       (select b.name, sum(bytes / 1024 / 1024) total_space
          from sys.v_$datafile a, sys.v_$tablespace b
         where a.ts# = b.ts#
         group by b.name) t
 where free.tablespace_name = t.name

Oracle DBA常用查询的更多相关文章

  1. Oracle DBA 常用查询

    1. 查询系统所有对象 select owner, object_name, object_type, created, last_ddl_time, timestamp, statusfrom db ...

  2. oracle数据库常用查询一

    oracle数据库常用查询一 sqlplus / as sysdba; 或sqlplus sys/密码 as sysdba;两者都是以sys登录.conn scott/tiger@orcl; conn ...

  3. ORACLE数据库常用查询二

    ORACLE数据库常用查询 1.查看表空间对应数据文件情况: SQL MB,AUTOEXTENSIBLE FROM DBA_DATA_FILES; TABLESPACE_NAME FILE_NAME ...

  4. Oracle DBA常用的系统表

    1.2 DBA常用的表1.2.1  dba_开头    dba_users数据库用户信息    dba_segments  表段信息    dba_extents    数据区信息    dba_ob ...

  5. Oracle DBA常用SQL

    监控SQL 1.监控事例的等待: select event,sum(decode(wait_time,0,0,1)) prev, sum(decode(wait_time,0,1,0)) curr,c ...

  6. ORACLE数据库管理常用查询语句

    /*查看表空间的名称及大小*/ SELECT t.tablespace_name, round(SUM(bytes / (1024 * 1024)), 0) ts_size FROM dba_tabl ...

  7. Oracle数据库常用查询语句

    1.[oracle@dbserver ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 15 15:1 ...

  8. Oracle管理常用查询语句

    1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom dba_tablespaces ...

  9. oracle DBA 常用表和视图

    ☆dba_开头.....   dba_users      数据库用户信息   dba_segments  表段信息   dba_extents    数据区信息   dba_objects    数 ...

随机推荐

  1. Android 6.0权限适配

    targetSdkVersion 23以上,必须适配新的权限模式 安卓6.0及之后,权限分为三类  1.不涉及隐私的正常权限,如innernet2.危险权限 3.特殊权限 system_alert_w ...

  2. Monkey基础

    一.Monkey工具简介 Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序 ...

  3. Matlab中的一些小技巧

    (转于它处,仅供参考) 1.. Ctrl+C 中断正在执行的操作 如果程序不小心进入死循环,或者计算时间太长,可以在命令窗口中使用Ctrl+c来中断.MATLAB这时可能正疲于应付,响应会有些滞后. ...

  4. Sql With as 用法

    with district as (     select  * from Area where AbbrTW= N'中國'     union all     select  a.* from Ar ...

  5. Eclipse编程时的快捷键总结

    " alt + / " 快捷键是代码补全功能 输入" syso alt + / "会自动补全成System.out.println();

  6. 新版本eclipse Neon 4.6.1,登录git报401 没有权限

    新版本eclipse Neon 4.6.1,登录git报401 没有权限 经过查找原因竟然是新的eclipse需要进行update.比较坑,新版eclipse竟然需要先更新一下才能用! eclipse ...

  7. 读《JavaScript DOM编程艺术》

    国庆假期花了三四天看了这本书,书很薄,因为是入门书,干货也不是很多. 4. childNodes nodeType nodeValue firstChild lastChild childNodes返 ...

  8. ASP.NET Misconfiguration: Debug Information

    Abstract: Debugging messages help attackers learn about the system and plan a form of attack. Explan ...

  9. php 文件锁

    当写为LOCK_EX锁 且 读为LOCK_SH锁时最为妥当,经测试,这时情况如下: 1, 先运行w.php,马上支行r.php 后 程序会先等写入后再读取 2, 先运行r.php,再马上支行w.php ...

  10. jquery ajax get /post

    $.get(URL,callback); $("button").click(function(){ $.get("demo_test.asp",functio ...