表空間相關命令及查詢SQL

2021-12-30 10:19:26 字數 2077 閱讀 8973

表空間相關命令及查詢sql

1、刪除表空間及資料檔案

drop tablespace ts_global_01 including contents and datafiles;

2、離線刪除資料檔案  www.2cto.com  

alter database datafile '/oradata/dtcdb/ts_index_02' offline drop;

3、自動回滾表空間檔案刪除

alter tablespace undotbs add datafile '/oradata/dtcdb/undotbs_01.dbf';

4、建立自動回滾表空間檔案

create undo tablespace undotbs02 datafile '/oradata/dtcdb/undotbs_02.dbf' size 10m;

5、查詢段、資料檔案資訊

select distinct t1.owner, /*t1.segment_name,*/ t1.segment_type, t1.segment_subtype, t2.*

from dba_segments t1, dba_data_files t2

where t1.tablespace_name = t2.tablespace_name

--and t2.file_name = '/opt/oracle/11g/dbs/ts_index_01'

and t2.tablespace_name = 'ts_index_01'

order by t1.owner, t2.file_name

www.2cto.com  

select t.file# ,t.status,t1.file_name from v$datafile t ,dba_data_files t1 where  t.file# = t1.file_id and t.status='recover';

6、清空全域性**管理器

purge dba_recyclebin;

7、查詢所有段資訊

select t.owner, sum(t.bytes) / 1024 / 1024 / 1024 as size_g

from dba_segments t

--where t.segment_type = 'table'

group by t.owner

order by t.owner;

8、查詢表空間檔案所佔物理空間

select t.tablespace_name,

trunc(t.bytes / 1024 / 1024 / 1024, 3) as size_g,

t.file_name,

t.online_status

from dba_data_files t

where t.tablespace_name like 'ts_%'

and t.bytes / 1024 / 1024 / 1024 > 1

order by t.tablespace_name,size_g desc, t.file_name;

9、查詢資料檔案的狀態資訊

select file#,name,status,enabled,bytes/1024/1024 m from v$datafile t

where t.name='/oradata/dtcdb/ts_index_02'

10、查詢資料庫系統檔案資訊  www.2cto.com  

select * from sys.file$

11、資料庫檔案恢復操作

shutdown abort;

a、恢復成功

startup mount;

recover datafile '/oradata/dtcdb/ts_partition_a_000';

alter database open;

b、恢復失敗

startup mount;

alter database datafile '/oradata/dtcdb/ts_partition_a_000' offline drop;

alter database open;  

作者 attagain

oracle 表空間相關查詢

查詢表空間使用情況 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 b...

sql 資料庫 表空間 ,使用者 相關命令

隨便 保留出處 檢視所有資料庫 show databases 建立新資料庫 create datebase dbname 登陸後用此命令建立 create database dbname default character set utf8 collate utf8 general ci 建立資料庫...

sql資料表及資料占用空間查詢

一 查詢某個資料表占用空間大小 code exec sp spaceused 表名稱 二 迴圈讀取資料庫中所有表,並查詢出每張表所占用的空間大小 code 建立乙個臨時表 use dbname create table tabspaceused name nvarchar 100 row char ...