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. chrome网页重定向

    使用chrome浏览器打开某网页时总会出现错误:此网页包含重定向循环 解决办法: 关闭chrome浏览器, 到你的机器的:C:\Users\username\AppData\Local\Google\ ...

  2. rabbitMQ学习(六)

    请求模式 客户端: import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.Connection; impor ...

  3. Build OpenCV text(OCR) module on windows

    Background. AOI software needs to use the OCR feature to recognize the texts on the chips. Because o ...

  4. BCB中实现拖拽Panel 改变位置和大小的代码

    //--------------------------------------------------------------------------- #ifndef Unit1H #define ...

  5. WCF Misconfiguration: Security Not Enabled

    Abstract: No transport or message security has been defined. Explanation: Applications that transmit ...

  6. Java中的自增问题(i=i++)

    也许我这是在较真, 但是我们确实有时候就不小心就错写为这种情况了. 看如下代码: public class Test{ public static void main(String[] args){ ...

  7. MVC Cookie的使用

    1.创建Cookies有两种方法: Response.Cookies["userName"].Value = "patrick"; Response.Cooki ...

  8. c++多态

    #include <cstdio> using namespace std; class Base { public: virtual void A() { puts("Base ...

  9. 一个不错的loading效果--IT蓝豹

    一个不错的loading效果 介绍:一个不错的loading加载效果,弹性收缩,效果不错,学习android动画的朋友可以下载来研究研究本例子其实由SeekBar实现,由MetaballView,Me ...

  10. c#利用反射获取对象属性值

    public static string GetObjectPropertyValue<T>(T t, string propertyname){     Type type = type ...