--查询表空间、表空间大小及表空间对应物理路径

select a.tablespace_name,b.file_name,a.block_size,a.block_size,b.bytes/1024

/1024 "Sum MB" from dba_tablespaces a,dba_data_files b where a.tablespace_name=b.tablespace_name;

--查询表空间使用情况

  SELECT UPPER(F.TABLESPACE_NAME) "表空间名",

  D.TOT_GROOTTE_MB "表空间大小(M)",

  D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",

  TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') || '%' "使用比",

  F.TOTAL_BYTES "空闲空间(M)",

  F.MAX_BYTES "最大块(M)"

  FROM (SELECT TABLESPACE_NAME,

  ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,

  ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES

  FROM SYS.DBA_FREE_SPACE

  GROUP BY TABLESPACE_NAME) F,

  (SELECT DD.TABLESPACE_NAME,

   ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB

  FROM SYS.DBA_DATA_FILES DD

  GROUP BY DD.TABLESPACE_NAME) D

  WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME

  ORDER BY 1;

--查询表空间的free space

  select tablespace_name,

  count(*) as extends,

  round(sum(bytes) / 1024 / 1024, 2) as MB,

  sum(blocks) as blocks

  from dba_free_space

group by tablespace_name;

--查询表空间的总容量

  select tablespace_name, sum(bytes) / 1024 / 1024 as MB

  from dba_data_files

  group by tablespace_name;

--查询表空间使用率

  select total.tablespace_name,

  round(total.MB, 2) as Total_MB,考试大论坛

  round(total.MB - free.MB, 2) as Used_MB,

  round((1 - free.MB / total.MB) * 100, 2) || '%' as Used_Pct

  from (select tablespace_name, sum(bytes) / 1024 / 1024 as MB

  from dba_free_space

  group by tablespace_name) free,

  (select tablespace_name, sum(bytes) / 1024 / 1024 as MB

  from dba_data_files

  group by tablespace_name) total

  where free.tablespace_name = total.tablespace_name;

1.查找当前表级锁的SQL如下:

select sess.sid,

sess.serial#,

lo.oracle_username,

lo.os_user_name,

ao.object_name,

lo.locked_mode

from v$locked_object lo,

dba_objects ao,

v$session sess

where ao.object_id = lo.object_id and lo.session_id = sess.sid;

2.杀掉锁表进程:

alter system kill session '436,35123';

3.RAC环境中锁查找:

SELECT inst_id,DECODE(request,0,'Holder: ','Waiter: ')||sid sess,

id1, id2, lmode, request, type,block,ctime

FROM GV$LOCK

WHERE (id1, id2, type) IN

(SELECT id1, id2, type FROM GV$LOCK WHERE request>0)

ORDER BY id1, request;

4.监控当前数据库谁在运行什么SQL语句

select osuser, username, sql_text

from  v$session a, v$sqltext b

where  a.sql_address =b.address order by address, piece;

5.找使用CPU多的用户session

select a.sid,spid,status,substr(a.program,1,40) prog, a.terminal,osuser,value/60/100 value

from  v$session a,v$process b,v$sesstat c

where  c.statistic#=12 and

c.sid=a.sid and

a.paddr=b.addr

order by value desc;

6.查看死锁信息

SELECT (SELECT username

FROM v$session

WHERE SID = a.SID) blocker, a.SID, 'is blocking',

(SELECT username

FROM v$session

WHERE SID = b.SID) blockee, b.SID

FROM v$lock a, v$lock b

WHERE a.BLOCK = 1 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2;

7.具有最高等待的对象

SELECT   o.OWNER,o.object_name, o.object_type, a.event,

SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, dba_objects o

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

AND a.current_obj# = o.object_id

GROUP BY o.OWNER,o.object_name, o.object_type, a.event

ORDER BY total_wait_time DESC;

SELECT   a.session_id, s.osuser, s.machine, s.program, o.owner, o.object_name,

o.object_type, a.event,

SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, dba_objects o, v$session s

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

AND a.current_obj# = o.object_id

AND a.session_id = s.SID

GROUP BY o.owner,

o.object_name,

o.object_type,

a.event,

a.session_id,

s.program,

s.machine,

s.osuser

ORDER BY total_wait_time DESC;

8.查询当前连接会话数

select s.value,s.sid,a.username

from

v$sesstat S,v$statname N,v$session A

where

n.statistic#=s.statistic# and

name='session pga memory'

and s.sid=a.sid

order by s.value;

9.等待最多的用户

SELECT   s.SID, s.username, SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, v$session s

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

GROUP BY s.SID, s.username

ORDER BY total_wait_time DESC;

10.等待最多的SQL

SELECT   a.program, a.session_id, a.user_id, d.username, s.sql_text,

SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, v$sqlarea s, dba_users d

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

AND a.sql_id = s.sql_id

AND a.user_id = d.user_id

GROUP BY a.program, a.session_id, a.user_id, s.sql_text, d.username;

11.查看消耗资源最多的SQL

SELECT hash_value, executions, buffer_gets, disk_reads, parse_calls

FROM V$SQLAREA

WHERE buffer_gets > 10000000 OR disk_reads > 1000000

ORDER BY buffer_gets + 100 * disk_reads DESC;

12.查看某条SQL语句的资源消耗

SELECT hash_value, buffer_gets, disk_reads, executions, parse_calls

FROM V$SQLAREA

WHERE hash_Value = 228801498 AND address = hextoraw('CBD8E4B0');

13.查询会话执行的实际SQL

SELECT   a.SID, a.username, s.sql_text

FROM v$session a, v$sqltext s

WHERE a.sql_address = s.address

AND a.sql_hash_value = s.hash_value

AND a.status = 'ACTIVE'

ORDER BY a.username, a.SID, s.piece;

14.显示正在等待锁的所有会话

SELECT * FROM DBA_WAITERS;

DDL

--------------------------------------------------------------

/*注意点:

1.如果在PL/SQL 等工具里打开的话,直接修改下面的代码中[斜体加粗部分]执行

2.确保路径存在,比如【D:\oracle\oradata\Oracle9i\】也就是你要保存文件的路径存在

/*分为四步 */

/*第1步:创建临时表空间  */

create temporary tablespace user_temp

tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'

size 50m

autoextend on

next 50m maxsize 20480m

extent management local;

/*第2步:创建数据表空间  */

create tablespace user_data

logging

datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'

size 50m

autoextend on

next 50m maxsize 20480m

extent management local;

/*第3步:创建用户并指定表空间  */

create user username identified by password

default tablespace user_data

temporary tablespace user_temp;

/*第4步:给用户授予权限  */

grant connect,resource,dba to username;

Oracle维护常用SQL的更多相关文章

  1. Oracle DBA常用SQL

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

  2. Oracle数据库常用Sql语句大全

    一,数据控制语句 (DML) 部分 1.INSERT  (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……); INSE ...

  3. Oracle之常用sql

    SQL函数 本文PDF下载 本文示例数据库下载 一旦成功地从表中检索出数据,就需要进一步操纵这些数据,以获得有用或有意义的结果.这些要求包括:执行计算与数学运算.转换数据.解析数值.组合值和聚合一个范 ...

  4. oracle数据库常用SQL语句(11.29更新)

    笔者日常工作中常用到的sql语句,现总结如下,留作日后查看. 1.按照两列中的最大值取 ,只取两列其中的一列 SELECT * FROM t_doc T ORDER BY GREATEST(T.Loa ...

  5. Oracle数据库常用SQL函数

    1.SQL函数的概念: 函数一般是在数据上执行的,它给数据的转换和处理提供了方便.只是将取出的数据进行处理,不会改变数据库中的值.(类似于java中的方法但函数只是将数据库中的数据取出(复制)到函数中 ...

  6. [转] Oracle数据库维护常用SQL语句集合

           原文地址 进程相关: 1. 求当前会话的SID,SERIAL# SELECT Sid, Serial# FROM V$session WHERE Audsid = Sys_Context ...

  7. oracle数据库常用SQL语句

    1)删除表的一列 ALTER TABLE 表名 DROP COLUMN 列名; 2)增加表的一列 且默认值为0 alter table 表名 add 字段名 类型 default '0'; 3)修改表 ...

  8. Oracle不常用SQL

    Oracle 查询最近创建的表 select * from user_objects where object_type='TABLE' order by created desc Oracle 查询 ...

  9. Oracle 数据库常用SQL语句(2)查询语句

    一.SQL基础查询 1.select语句 格式:select 字段 from 表名; 2.where 用于限制查询的结果. 3.查询条件 > < >= <= = != 4.与 ...

随机推荐

  1. 集合视图控制器(CollectionViewController) 、 标签控制器(TabBarController) 、 高级控件介绍

    1 创建集合视图,设置相关属性以满足要求 1.1 问题 集合视图控制器UIConllectionViewController是一个展示大量数据的控制器,系统默认管理着一个集合视图UICollectio ...

  2. C++学习笔记5:如何给变量及函数命名?

    1.遵循C++规定的变量及函数命名方法: 2.原则:简单,易于理解: 以下是一些例子,可以作为参考: //bad examples: int ccount;//Nobody knows what a ...

  3. HTML-day-1-HTML基础知识

    HTML基础知识 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  4. tensorflow0.8.0 安装配置

    参考官网:https://www.tensorflow.org/  Ubuntu15.10 + Eclipse Mars.2(4.5.2)官网最新 + Anaconda3-4.0.0 + Pydev4 ...

  5. Windows RPC Demo实现

    Windows RPC Demo实现 本文参考并整理以下相关文章 1. <远程过程调用> -百度百科 2. <RPC 编程> -http://www.ibm.com/devel ...

  6. 137. Single Number II

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  7. jQuery停止动画和判断是否处于动画状态

    1.停止元素的动画 stop([clearQueue][,gotoEnd]); 参数clearQHCHC和gotoEnd都足町选的参数,为Boolean值(ture或flase).clearQueue ...

  8. 顺序表及其多种实现方式 --- C/C++

    所谓顺序表,即线性表的顺序存储结构.下面给出的是数据结构---线性表的定义. ADT List{ 数据对象: 线性表的数据对象的集合为{a1,a2,a3,...,an},每个元素的类型为ElemTyp ...

  9. 带百分号的数据转json

    今天处理前后数据传输的时候遇到了问题. 前台拼参数是这样写的 '&rowData=' + JSON.stringify(rowData); 后台解析出的对象却总是null,而且没有抛Parse ...

  10. 最长不下降子序列的O(n^2)算法和O(nlogn)算法

    一.简单的O(n^2)的算法 很容易想到用动态规划做.设lis[]用于保存第1~i元素元素中最长不下降序列的长度,则lis[i]=max(lis[j])+1,且num[i]>num[j],i&g ...