---
title: "查询所有的oracle表、表空间、数据库连接等信息"
author: "dingshuo168"
date: "2012-03-19T10:22:59Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2012-03-19T10:22:49Z"
id: 1457321
url: "https://DSH.iteye.com/blog/1457321"
---

--查询所有的oracle表、表空间、数据库连接等信息  
   
\--1.查询表大小  
select table\_name, num\_rows, avg\_row\_len,  num\_rows * avg\_row\_len  
      -- ,   'delete from ' || table\_name || ';'  
  from user\_tables t  
 order by num\_rows * avg\_row\_len desc;

--2.查询表空间路径-------  
select * from dba\_data\_files t  
where t.tablespace\_name = 'USERS';

--3.查询表空间容量-----------  
select dbf.tablespace\_name,  
dbf.totalspace "总量(M)",  
dbf.totalblocks as 总块数,  
dfs.freespace "剩余总量(M)",  
dfs.freeblocks "剩余块数",  
(dfs.freespace / dbf.totalspace) * 100 "空闲比例"  
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);

--4数据库连接管理  
select count(\*) from v$process;  
select value from v$parameter where name = 'processes';  
  SELECT osuser, a.username,cpu\_time/executions/1000000||'s', sql\_fulltext,machine  
  from v$session a, v$sqlarea b  
  where a.sql\_address =b.address order by cpu\_time/executions desc;