随笔 - 1357  文章 - 0  评论 - 1104  阅读 - 1941万

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. 查看数据库安装实例(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
posted on   Ruthless  阅读(3696)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
历史上的今天:
2011-06-24 socket案例二
2011-06-24 socket案例一
2011-06-24 树TreePanel
2011-06-24 表格GridPanel
2011-06-24 表单Ext.form.FormPanel
2011-06-24 布局Layout
< 2025年3月 >
23 24 25 26 27 28 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 2 3 4 5

点击右上角即可分享
微信分享提示