ORACLE数据库管理常用查询语句
/*查看表空间的名称及大小*/
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 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;
/*查找object为哪些进程所用*/
SELECT p.spid,
s.sid,
s.type,
s.serial# serial_num,
s.username user_name,
a.type object_type,
s.osuser os_user_name,
a.owner,
a.object object_name,
decode(sign(48 - command),
1,
to_char(command),
'Action Code #' || to_char(command)) action,
p.program oracle_process,
s.terminal terminal,
s.program program,
s.status session_status
FROM v$session s, v$access a, v$process p
WHERE s.paddr = p.addr
AND s.type = 'USER'
AND a.sid = s.sid
AND a.object = 'SUBSCRIBER_ATTR'
ORDER BY s.username, s.osuser;
/*查看回滚段名称及大小*/
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 version
FROM product_component_version
WHERE substr(product, 1, 6) = 'Oracle';
/*查看数据库的创建日期和归档方式*/
SELECT created, log_mode, log_mode FROM v$database;
/*捕捉运行很久的SQL*/
column username format a12 column opname format a16 column progress format a8
SELECT username,
sid,
opname,
round(sofar * 100 / totalwork, 0) || '%' AS progress,
time_remaining,
sql_text
FROM v$session_longops, v$sql
WHERE time_remaining <> 0
AND sql_address = address
AND sql_hash_value = hash_value;
/*查看数据表的参数信息*/
SELECT partition_name,
high_value,
high_value_length,
tablespace_name,
pct_free,
pct_used,
ini_trans,
max_trans,
initial_extent,
next_extent,
min_extent,
max_extent,
pct_increase,
freelists,
freelist_groups,
logging,
buffer_pool,
num_rows,
blocks,
empty_blocks,
avg_space,
chain_cnt,
avg_row_len,
sample_size,
last_analyzed
FROM dba_tab_partitions
--WHERE table_name = :tname AND table_owner = :towner
ORDER BY partition_position;
/*查看还没提交的事务*/
SELECT * FROM v$locked_object;
SELECT * FROM v$transaction;
/*回滚段查看*/
SELECT rownum,
sys.dba_rollback_segs.segment_namename,
v$rollstat.extents extents,
v$rollstat.rssize size_in_bytes,
v$rollstat.xacts xacts,
v$rollstat.gets gets,
v$rollstat.waits waits,
v$rollstat.writes writes,
sys.dba_rollback_segs.status status
FROM v$rollstat, sys.dba_rollback_segs, v$rollname
WHERE v$rollname.name(+) = sys.dba_rollback_segs.segment_name
AND v$rollstat.usn(+) = v$rollname.usn
ORDER BY rownum;
/*耗资源的进程(top session)*/
SELECT s.schemaname schema_name,
decode(sign(48 - command),
1,
to_char(command),
'Action Code #' || to_char(command)) action,
status session_status,
s.osuser os_user_name,
s.sid,
p.spid,
s.serial# serial_num,
nvl(s.username, '[Oracle process]') user_name,
s.terminal terminal,
s.program program,
st.value criteria_value
FROM v$sesstat st, v$session s, v$process p
WHERE st.sid = s.sid
AND st.statistic# = to_number('38')
AND ('ALL' = 'ALL' OR s.status = 'ALL')
AND p.addr = s.paddr
ORDER BY st.value DESC, p.spid ASC, s.username ASC, s.osuser ASC;
/*查看锁(lock)情况*/
SELECT /*+ RULE */
ls.osuser os_user_name,
ls.username user_name,
decode(ls.type,
'RW',
'Row wait enqueue lock',
'TM',
'DML enqueue lock',
'TX',
'Transaction enqueue lock',
'UL',
'User supplied lock') lock_type,
o.object_name OBJECT,
decode(ls.lmode,
1,
NULL,
2,
'Row Share',
3,
'Row Exclusive',
4,
'Share',
5,
'Share Row Exclusive',
6,
'Exclusive',
NULL) lock_mode,
o.owner,
ls.sid,
ls.serial# serial_num,
ls.id1,
ls.id2
FROM sys.dba_objects o,
(SELECT s.osuser,
s.username,
l.type,
l.lmode,
s.sid,
s.serial#,
l.id1,
l.id2
FROM v$session s, v$lock l
WHERE s.sid = l.sid) ls
WHERE o.object_id = ls.id1
AND o.owner <> 'SYS'
ORDER BY o.owner, o.object_name;
/*查看等待(wait)情况*/
SELECT v$waitstat.class,
v$waitstat.count COUNT,
SUM(v$sysstat.value) sum_value
FROM v$waitstat, v$sysstat
WHERE v$sysstat.name IN ('db block gets', 'consistent gets')
GROUP BY v$waitstat.class, v$waitstat.count;
/*查看SGA情况*/
SELECT NAME, bytes
FROM sys.v_$sgastat
ORDER BY NAME ASC
/*查看数据表的全部索引列*/
SELECT c.index_name, i.uniqueness, c.column_name
FROM user_indexes i, user_ind_columns c
WHERE i.index_name = c.index_name
AND i.table_name = upper('hr_locations_all')
ORDER BY c.index_name,
c.column_position
/*查看低效运行的SQL语句*/
SELECT executions,
disk_reads,
buffer_gets,
round((buffer_gets - disk_reads) / buffer_gets,
2) hit_radio,
round(disk_reads / executions, 2) reads_per_run,
sql_text
FROM v$sqlarea
WHERE executions > 0
AND buffer_gets > 0
AND (buffer_gets - disk_reads) / buffer_gets < 0.8
ORDER BY 4 DESC; /*查询有哪些用户在使用数据库*/
SELECT username FROM v$session;
/*查看数据库的SID:*/
SELECT NAME FROM v$database;
--也可以直接查看 init.ora文件
/*如何在Oracle服务器上通过SQLPLUS查看本机IP地址 :*/
SELECT sys_context('userenv', 'ip_address') FROM dual;
ORACLE数据库管理常用查询语句的更多相关文章
- Oracle数据库常用查询语句
1.[oracle@dbserver ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 15 15:1 ...
- Oracle管理常用查询语句
1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom dba_tablespaces ...
- Oracle中分页查询语句
Oracle分页查询语句使我们最常用的语句之一,下面就为您介绍的Oracle分页查询语句的用法,如果您对此方面感兴趣的话,不妨一看. Oracle分页查询语句基本上可以按照本文给出的格式来进行套用.O ...
- Oracle DBA常用查询
Oracle DBA常用查询 –1. 查询系统所有对象select owner, object_name, object_type, created, last_ddl_time, timestamp ...
- 23个MySQL常用查询语句
23个MySQL常用查询语句 一查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!> ...
- oracle数据库常用查询一
oracle数据库常用查询一 sqlplus / as sysdba; 或sqlplus sys/密码 as sysdba;两者都是以sys登录.conn scott/tiger@orcl; conn ...
- ORACLE数据库常用查询二
ORACLE数据库常用查询 1.查看表空间对应数据文件情况: SQL MB,AUTOEXTENSIBLE FROM DBA_DATA_FILES; TABLESPACE_NAME FILE_NAME ...
- Oracle的分页查询语句优化
Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. (一) 分页查询格式: SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT ...
- Oracle执行SQL查询语句的步骤
Oracle执行SQL查询语句的步骤 如果用户在SQL*Plus下输入了如下查询语句:SELECT * FROM dept: 查询语句的处理主要包括三个过程:编译(parse).执行(execute) ...
随机推荐
- [LeetCode] Split Array into Consecutive Subsequences 将数组分割成连续子序列
You are given an integer array sorted in ascending order (may contain duplicates), you need to split ...
- 实战分享:如何成功防护1.2T国内已知最大流量DDoS攻击
作者:腾讯云宙斯盾安全团队&腾讯安全平台部 引言: DDoS攻击势头愈演愈烈,除了攻击手法的多样化发展之外,最直接的还是攻击流量的成倍增长.3月份国内的最大规模DDoS攻击纪录还停留在数百G规 ...
- IIS&ASP.NET 站点IP跳转到域名
前言:先到微软的 https://www.iis.net/downloads/microsoft/url-rewrite 下载URL Rewrite 目标:输入ip跳转到域名所在的网站 比如58的1 ...
- 毕业回馈--89C51keil工程的创建
声明:毕业回馈类博客均为大学毕业前夕同同学共享内容.为了给大学做一个总结,报答母校的栽培,才发起这样一个活动. ******************************************** ...
- 迎圣诞,拿大奖活动赛题_SQLi(sprintf格式化字符)
看题目应该就是注入没跑了 先拿正常输入试试,输了admin,admin,结果返回password error!,说明还真的存在admin账户 拿常规注入语句试探一下admin' and 1=1%23, ...
- SAC E#1 - 一道神题 Sequence1
题目背景 小强和阿米巴是好朋友. 题目描述 小强很喜欢数列.有一天,他心血来潮,写下了一个数列. 阿米巴也很喜欢数列.但是他只喜欢其中一种:波动数列. 一个长度为n的波动数列满足对于任何i(1 < ...
- bzoj 5251: [2018多省省队联测]劈配
Description 一年一度的综艺节目<中国新代码>又开始了. Zayid从小就梦想成为一名程序员,他觉得这是一个展示自己的舞台,于是他毫不犹豫地报名了. 题目描述 轻车熟路的Zayi ...
- ●POJ 1990 MooFest
题链: http://poj.org/problem?id=1990 题解: 树状数组 把牛们按x坐标从小到大排序,依次考虑每头牛对左边和对右边的贡献. 对左边的贡献:从左向右枚举牛,计算以当前牛的声 ...
- hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)
Mart Master II Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- bzoj 1085: [SCOI2005]骑士精神
Description 在一个5×5的棋盘上有12个白色的骑士和12个黑色的骑士,且有一个空位.在任何时候一个骑士都能按照骑士的走法(它可以走到和它横坐标相差为1,纵坐标相差为2或者横坐标相差为2,纵 ...