oracle表空间
2019-06-04 9:41:50
by 山阴客

打印???
少达网(http://www.shaoda.com)
技术文章(http://www.shaoda.comhref=category.php?cid=1)

oracle表空间


--修改表空间自动增长 每次50M 最大32G
--ALTER DATABASE DATAFILE 'E:\ORADATA\INCABACK.DBF'  AUTOEXTEND ON NEXT 50M MAXSIZE 34359721984;  

--修改表空间 增加表空间文件
--ALTER TABLESPACE USERS ADD DATAFILE 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS03.DB' size 1000M;增加表空间

--ALTER DATABASE DATAFILE 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS02.DB' AUTOEXTEND ON NEXT 50M MAXSIZE 34359721984;  

--查询表空间使用大小

select owner, tablespace_name, round(sum(BYTES) / 1024 / 1024, 2) "USED(M)"
  FROM DBA_SEGMENTS
 GROUP BY owner, tablespace_name

 ORDER BY SUM(BYTES) desc;

SELECT * FROM DBA_TABLESPACES; -- 记录各个表空间的详细信息
SELECT * FROM DBA_TABLESPACE_USAGE_METRICS; -- 记录各个表空间的使用状况
SELECT * FROM DBA_DATA_FILES; -- 记录各个数据文件的详细信息
SELECT * FROM DBA_SEGMENTS; -- 记录各个段的详细信息,与 DBA_TABLES,DBA_INDEXES,DBA_LOBS,DBA_PART_TABLES,DBA_PART_INDEXES,DBA_PART_LOBS,DBA_OBJECTS 搭配使用
SELECT * FROM DBA_LOBS; --BLOB 字段所对应的字段名称
SELECT * FROM DBA_INDEXES; -- 分区索引需要通过 DBA_INDEXS 来找到对应的表名
SELECT * FROM DBA_EXTENTS; -- 记录各个区间对象的详细信息 
select * from dba_users;

--查询表空间 名称 表空间文件  是否自动增长  现在大小,最大的大小
SELECT T.TABLESPACE_NAME,
       D.FILE_NAME,
       D.AUTOEXTENSIBLE,
       D.BYTES,
       D.MAXBYTES,
       D.STATUS
  FROM DBA_TABLESPACES T, DBA_DATA_FILES D
 WHERE T.TABLESPACE_NAME = D.TABLESPACE_NAME
 ORDER BY TABLESPACE_NAME, FILE_NAME;

select a.FILE_NAME, a.AUTOEXTENSIBLE, a.MAXBYTES, a.INCREMENT_BY
  from dba_data_files a;

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 4 DESC;

select a.tablespace_name as "表空间名",
       a.bytes / 1024 / 1024 as "表空间大小(M)",
       (a.bytes - b.bytes) / 1024 / 1024 as "已使用空间(M)",
       b.bytes / 1024 / 1024 "空闲空间(M)",
       round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "使用比"
  from (select tablespace_name, sum(bytes) bytes
          from dba_data_files
         group by tablespace_name) a,
       (select tablespace_name, sum(bytes) bytes, max(bytes) largest
          from dba_free_space
         group by tablespace_name) b
 where a.tablespace_name = b.tablespace_name

--查询oracle中所有用户信息
  select * from dba_users;

--只查询用户和密码
select username, password from dba_users;
--查询当前用户信息
select * from dba_ustats;

--oracle无法删除当前连接用户方法

select username, sid, serial#
  from v$session
 where username = 'INCABACK1'

 alter system kill session '823,19972';
alter system kill session '279,42682';

alter system kill session '151,6245';

select saddr, sid, serial#, paddr, username, status
  from v$session
 where username is not null
 



Copyright © 2002-2022 http://www.shaoda.com
All rights reserved.

备案号:浙ICP备17002154号-5 Powered by: myarticle.com.cn Version 1.0dev
Processed Time: 0.0015 s Querys: 4 [ Gzip Level 0 ]