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. 时间序列分析之ARIMA模型预测__R篇

    http://www.cnblogs.com/bicoffee/p/3838049.html

  2. iOS内存管理

    iOS内存管理的方式是引用计数机制.分为MRC(人式引用计数)和ARC(自动引用计数). 为什么要学习内存管理? 内存管理方式是引用计数机制,通过控制对象的引用计数来实现操作对象的功能.一个对象的生命 ...

  3. python 常用高效代码写法集锦

    一.打开文件 #使用 with 语句操作文件对象 with open(r'somefileName') as somefile: for line in somefile: print line # ...

  4. maven增加自定义jar包

    1.博客来源: http://www.cnblogs.com/leiOOlei/p/3356834.html 导入平台SDK的方法 mvn install:install-file -DgroupId ...

  5. web初学之request,session与application

    request (1)request的setAttribute()与getAttribute()方法一般都是成对出现,首先通过setAttribute()方法设置属性与属性值,然后通过getAttri ...

  6. mysql 允许远程访问

    原来装mysql数据库的时候就想,这个只要在本地访问就可以了,没有必要让远程访问.可是,今天想把数据放到远程的机器上,却发现,不是简单的将sql语句(指导出的语句)执行一遍就行了,对于那些自增的字段, ...

  7. U-boot中的FDT

    1. U-boot为了支持FDT,添加了新的代码:/libfdt目录fdt.h libfdt.h fdt_support.h fdt_support.c 2. http://blog.csdn.net ...

  8. UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用

    UIButton内有两个控件titleLabel和imageView,可以用来显示一个文本和图片,这里的图片区别于背景图片.给UIButton设 置了title和image后,它们会图片在左边,文本在 ...

  9. CocosCreator反射在Android中的使用

    CocosCreator反射在Android中的使用 新建一个CocosCreator项目,然后点击构建 构建完成之后,即可用AndroidStudio打开构建的项目 使用AndroidStudio打 ...

  10. Python--Argparse学习感悟

    笔者在https://docs.python.org/2/howto/argparse.html#id1上,学习到了argparse的基本概念和使用规范,学习过后忍不住将自己的一些体会和大家分享一下. ...