Oracle表空間維護總結
1. 概念:
表空間:最大的邏輯儲存檔案,與物理上的一個或多個資料檔案對應,每個資料庫至少擁有一個表空間,表空間的大小等於構成表空間的所有資料檔案的大小總和,用於儲存使用者在資料庫中儲存的所有內容。
2. 種類:
分為基本表空間、臨時表空間、大檔案表空間、非標準資料塊表空間和撤銷表空間。
基本表空間:用於儲存使用者的永久性資料
臨時表空間:排序、彙總時產生的臨時資料
大檔案表空間:儲存大型資料,如LOB
非標準資料塊表空間:建立資料塊大小不同的表空間
撤銷表空間:儲存事務的撤銷資料,在資料恢復時使用
3. 系統預設表空間:
system:系統表空間,用於儲存系統的資料字典、系統的管理資訊和使用者資料表等。
sysaux:輔助系統表空間,減少系統表空間負荷,體改系統作業效率,Oracle系統自動維護,一般不用於儲存資料結構。
temp:臨時表空間。
undotbsl:撤銷表空間,用於在自動撤銷管理方式下儲存撤銷資訊。
users:使用者表空間。
4. 表空間的狀態
表空間的狀態屬性主要有線上(online),離線(offline),只讀(read only)和讀寫(read write)。SQL> select
-- 檢視錶空間的狀態
select tablespace_name,status from dba_tablespaces;
-- 更改表空間狀態
alter tablespace XXX offline/online/read only/read write;
5. 建立表空間語句:
create [temporary|undo]tablespace tablespace_name[datafile|tempfile] 'filename' size
size K|M[reuse] //已經存在是否指定reuse
[autoextend off|on //資料檔案是否自動擴充套件
[next number K|M maxsize unlimited|number K|M]
][……]
[mininum extent number K|M]
[blocksize number K] //初始化引數資料庫大小,只能用於持久表空間
[online|offline] //online表空間可用
[logging|nologging]
[force logging]
[default storage storage] //設定預設儲存引數
[compress|nocompress] //壓縮資料段內數值
[premanent|temporary] //持久儲存資料庫物件|臨時
[extent management dictionary|local //資料字典管理方式|本地管理,一般本地
[autoallocate|uniform size number K|M]]
[segment space management auto|manual]; //表空間段的管理方式自動|手動
-- 建立臨時表空間:
create temporary tablespace XXXX tempfile 'XXXXXXXtemp.dbf' size 50m
autoextend on next 50m maxsize 20480m extent management local;
-- 建立資料表空間:
create tablespace KMYQ datafile '/oradata/testdb2/KMYQ01.dbf' size 200m
autoextend off
segment space management auto
extent management local
uniform size 4M;
-- 建立臨時表空間建立使用者並指定表空間:
create user XXXX identified by XXXXX default tablespace XXX temporary tablespace XXXX_temp;
6. 預設表空間:
初始狀態下(未修改)預設永久性表空間為system,臨時為temp
-- 查詢預設表空間:
select default_tablespace from user_users;
-- 查詢預設新使用者表空間與預設臨時表空間
SQL> col PROPERTY_VALUE for a40
select property_name,property_value
from database_properties where property_name
in ('DEFAULT_PERMANENT_TABLESPACE','DEFAULT_TEMP_TABLESPACE');
-- 修改預設臨時表空間:
alter database default tablespace XXXX;
7. 檢視錶空間物理檔案的名稱及大小
SELECT tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
FROM dba_data_files
ORDER BY tablespace_name;
8. 檢視錶空間的使用情況
資料表空間使用率:
SELECT a.tablespace_name,
a.bytes/(1024*1024) total_M,
b.bytes/(1024*1024) used_M,
c.bytes/(1024*1024) free_M,
(b.bytes * 100) / a.bytes "% USED ",
(c.bytes * 100) / a.bytes "% FREE "
FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
WHERE a.tablespace_name = b.tablespace_name
AND a.tablespace_name = c.tablespace_name;
臨時表空間使用率:
SELECT temp_used.tablespace_name,
total - used as "Free_M",
total as "Total_M",
round(nvl(total - used, 0) * 100 / total, 3) "Free percent"
FROM (SELECT tablespace_name, SUM(bytes_used) / 1024 / 1024 used
FROM GV_$TEMP_SPACE_HEADER
GROUP BY tablespace_name) temp_used,
(SELECT tablespace_name, SUM(bytes) / 1024 / 1024 total
FROM dba_temp_files
GROUP BY tablespace_name) temp_total
WHERE temp_used.tablespace_name = temp_total.tablespace_name;
9. 查詢表空間每天的使用情況
select a.name, b.*
from v$tablespace a,
(select tablespace_id,
trunc(to_date(rtime, 'mm/dd/yyyy hh24:mi:ss')) datetime,
max(tablespace_usedsize * 8 / 1024) used_size
from dba_hist_tbspc_space_usage
where trunc(to_date(rtime, 'mm/dd/yyyy hh24:mi:ss')) >
trunc(sysdate - 30) group by tablespace_id,
trunc(to_date(rtime, 'mm/dd/yyyy hh24:mi:ss')) order by
tablespace_id, trunc(to_date(rtime, 'mm/dd/yyyy hh24:mi:ss'))) b
where a.ts# = b.tablespace_id ;
10. 表空間擴容
-- 修改建立的資料檔案的大小
SQL> col file_name for a60
SQL> select file_name,bytes/1024/1024 from dba_data_files;
SQL> alter database datafile '/home/oracle/app/oradata/orcl/users01.dbf'resize 51M;
SQL> select file_name,bytes/1024/1024 from dba_data_files;
-- 增加表空間的資料檔案
SQL> alter tablespace andy add datafile '/home/oracle/app/oradata/orcl/andy02.dbf'size 1M
autoextend on next 1m maxsize 2m ;
11. 刪除表空間
-- 刪除所有資料庫物件與刪除資料檔案
drop tablespace XXX including contents and contents;
12. 重新命名錶空間
alter tablespace tablespace_name rename to new_table_name;
alter tablespace andy rename to newandy;
13. 移動表空間的資料檔案
SQL> select tablespace_name,file_name from dba_data_files where tablespace_name = 'NEWANDY';
SQL> alter tablespace newandy offline;
[oracle@11g ~]$ mv /home/oracle/app/oradata/orcl/andy01.dbf /home/oracle/app/oradata/andy01.dbf
SQL> alter tablespace newandy rename datafile '/home/oracle/app/oradata/orcl/andy01.dbf' to '/home/oracle/app/oradata/andy01.dbf';
SQL> alter tablespace newandy online;
SQL> select tablespace_name,file_name from dba_data_files where tablespace_name = 'NEWANDY';
14. 修改表空間的自動擴充套件性
SQL> select tablespace_name,status,extent_management,SEGMENT_SPACE_MANAGEMENT from dba_tablespaces;
SQL> alter database datafile file_name autoextend off|on [next number K|M maxsize unlimited|number K|M]
SQL> select tablespace_name,status,extent_management,SEGMENT_SPACE_MANAGEMENT from dba_tablespaces;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2136424/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle12c之 表空間維護總結Oracle
- oracle表空間管理維護Oracle
- oracle之 SYSAUX表空間維護OracleUX
- ORACLE臨時表空間總結Oracle
- Oracle的UNDO表空間管理總結Oracle
- undo表空間總結
- Oracle10g以上sysaux表空間的維護和清理OracleUX
- 【Oracle-資料庫維護】-刪除臨時表空間Oracle資料庫
- oracle的表空間、分割槽表、以及索引的總結Oracle索引
- 總結-表空間傳輸
- 關於oracle可傳輸表空間的總結Oracle
- 【臨時表空間組】臨時表空間組的建立、維護及應用
- Oracle常用維護語句總結Oracle
- 臨時表空間操作總結
- Oracle的邏輯結構(表空間、段、區間、塊)——表空間Oracle
- 關於oracle的表空間,分割槽表,以及索引的總結Oracle索引
- mysql關於表空間的總結MySql
- Oracle GoldenGate同步服務歸檔空間維護OracleGo
- 關於oracle的表空間,分割槽表,以及索引的總結(轉)Oracle索引
- 關於oracle的表空間,分割槽表,以及索引的總結 -- 轉Oracle索引
- 【TEMP】臨時表空間的工作原理及維護方法
- 資料庫維護常用操作4--表空間操作資料庫
- Oracle表空間Oracle
- 【TABLESPACE】Oracle 表空間結構說明Oracle
- Oracle基礎結構之表空間Oracle
- ORACLE-RAC的CRS維護命令總結Oracle
- oracle可傳輸表空間TTS小結OracleTTS
- ORACLE資料庫日常維護知識總結Oracle資料庫
- oracle temp 表空間Oracle
- 增加oracle表空間Oracle
- oracle undo 表空間Oracle
- oracle users 表空間Oracle
- Oracle表空間管理Oracle
- oracle建立表空間Oracle
- Oracle 表空間管理Oracle
- oracle表空間操作Oracle
- ORACLE MOVE表空間Oracle
- ORACLE表空間概述Oracle