oracle 表空間 相關

2021-05-27 14:03:18 字數 3233 閱讀 8876

檢視當前表空間:

select * from dba_tablespaces;
檢視剩餘表空間:

select tablespace_name,file_id,block_id,bytes/1024/1024,blocks from dba_free_space;
查詢資料檔案名稱、大小和路徑的資訊:

select tablespace_name,file_id,bytes/1024/1024,file_name from dba_data_files;
以mb的形式表示空間大小:bytes/1024/1024

建立表空間:

create tablespace test01

datafile 'd:\oracle\oradata\orcl\test01.dbf' size 500m

extent management local

autoallocate

segment space management auto;

select * from dba_tablespaces where tablespace_name = 'test01'

在linux下,datafile '/oracle/oradata/orcl/test01.dbf'

oracle關鍵字 不區分大小寫,資料區分大小寫

增加表空間的大小:

alter tablespace test01

add datafile 'd:\oracle\oradata\orcl\test01.dbf' size 650m;

alter tablespace test01 

add datafile 'd:\oracle\oradata\orcl\test01.dbf' size 650m

autoextend on

next 10m

maxsize 1000m

增加資料檔案的大小:

alter database datafile 'd:\oracle\oradata\orcl\data_01.dbf'
刪除表空間:

#表空間中包括 表或者索引 下面的命令將會出錯

drop tablespace test01;

#下面的命令刪除表空間和表空間的所有物件,但不能刪除物理檔案

drop tablespace test01 including contents;

#連同資料檔案一起刪除

drop tablespace test01 including contents and datafiles;

重新命名表空間:

alter tablespace test02 rename to test01;
唯讀表空間:

alter tablespace test01 read only

alter tablespace test01 read write;

進行唯讀的操作時,表空間狀態如下圖:status變成read only

select tablespace_name, 

block_size/1024,

initial_extent/1024,

max_extents/1024/1024,

extent_management,

allocation_type,

status

from dba_tablespaces

block_size:塊空間大小,oracle中資料存放的單位,預設為8k

initial_extent:區的初始化大小,預設為64k

max_extents:最大區大小,預設為2g

extent_managerment:區管理方式,本地管理,相對於10g之前的字典管理

allocation_type:區尺寸 的分配,除temp表空間之外,其餘都是自動分配

建立臨時表空間:

create temporary 

tablespace temp_demo4 tempfile 'd:\oracle\oradata\orcl\test04.dbf' size 200m

autoextend on

#windows 預設位置:

如果temofile 'test04.dbf',預設防在下面的路徑

$oracle_home\product\10.2.0\db_1\database\temp03.dbf

檢視臨時表空間:

select * from v$tempfile
更改臨時表空間:

alter tablespace temp add tempfile 'd:\oracle\product\10.2.0\db_1\database\temp05.dbf' size 500m reuse
重置乙個臨時檔案的大小:

alter database tempfile 'd:\oracle\oradata\orcl\test04.dbf' resize 255m
收縮臨時表空間:

1.區管理

oracle 需要增加尺寸的時候,空間就以區的方式新增給物件。

區的尺寸管理有兩種選擇:

uniform選項,需要使用size字句指定區的實際尺寸 ,如果省略size子句,預設1mb統一尺寸建立區

oracle區尺寸 選擇:小段64kb   中段1mb  大段64mb

2.段管理

使用可用列表(free list)和一對儲存引數(pctfree和pctused)

使用位圖管理

select initial_extent,next_extent,extent_management,allocation_type,

segment_space_management from dba_tablespaces

oracle表空間相關語句

1 檢視表空間檔案 select from dba data files 2 檢視使用者的預設表空間 select username,default tablespace from dba users 3 檢視表空間大小 select t.tablespace name,round sum byte...

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...

oracle傳輸表空間相關

1.convert tablespace convert tablespace源端庫執行 convert tablespace tps data to platform microsoft windows ia 32 bit format tmp u 2.convert datafile conve...