網站首頁 編程語言 正文
一、查看表空間使用率
1.查看數據庫表空間文件:
--查看數據庫表空間文件
select * from dba_data_files;
2.查看所有表空間的總容量:
--查看所有表空間的總容量
select dba.TABLESPACE_NAME, sum(bytes)/1024/1024 as MB
from dba_data_files dba
group by dba.TABLESPACE_NAME;
3.查看數據庫表空間使用率
--查看數據庫表空間使用率
select total.tablespace_name,round(total.MB, 2) as Total_MB,round(total.MB - free.MB, 2) as Used_MB,round((1-free.MB / total.MB)* 100, 2) || '%' as Used_Pct
from (
select tablespace_name, sum(bytes) /1024/1024 as MB
from dba_free_space group by tablespace_name) free,
(select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_data_files group by tablespace_name) total
where free.tablespace_name = total.tablespace_name
order by used_pct desc;
4.1.查看表空間總大小、使用率、剩余空間
--查看表空間總大小、使用率、剩余空間
select a.tablespace_name, total, free, total-free as used, substr(free/total * 100, 1, 5) as "FREE%", substr((total - free)/total * 100, 1, 5) as "USED%"
from
(select tablespace_name, sum(bytes)/1024/1024 as total from dba_data_files group by tablespace_name) a,
(select tablespace_name, sum(bytes)/1024/1024 as free from dba_free_space group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by a.tablespace_name
4.2.查看表空間使用率(包含temp臨時表空間)
--查看表空間使用率(包含臨時表空間)
select * from (
Select a.tablespace_name,
(a.bytes- b.bytes) "表空間使用大小(BYTE)",
a.bytes/(1024*1024*1024) "表空間大小(GB)",
b.bytes/(1024*1024*1024) "表空間剩余大小(GB)",
(a.bytes- b.bytes)/(1024*1024*1024) "表空間使用大小(GB)",
to_char((1 - b.bytes/a.bytes)*100,'99.99999') || '%' "使用率"
from (select tablespace_name,
sum(bytes) bytes
from dba_data_files
group by tablespace_name) a,
(select tablespace_name,
sum(bytes) bytes
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
union all
select c.tablespace_name,
d.bytes_used "表空間使用大小(BYTE)",
c.bytes/(1024*1024*1024) "表空間大小(GB)",
(c.bytes-d.bytes_used)/(1024*1024*1024) "表空間剩余大小(GB)",
d.bytes_used/(1024*1024*1024) "表空間使用大小(GB)",
to_char(d.bytes_used*100/c.bytes,'99.99999') || '%' "使用率"
from
(select tablespace_name,sum(bytes) bytes
from dba_temp_files group by tablespace_name) c,
(select tablespace_name,sum(bytes_cached) bytes_used
from v$temp_extent_pool group by tablespace_name) d
where c.tablespace_name = d.tablespace_name
)
order by tablespace_name
5.查看具體表的占用空間大小
--查看具體表的占用空間大小
select * from (
select t.tablespace_name,t.owner, t.segment_name, t.segment_type, sum(t.bytes / 1024 / 1024) mb
from dba_segments t
where t.segment_type='TABLE'
group by t.tablespace_name,t.OWNER, t.segment_name, t.segment_type
) t
order by t.mb desc
二、擴展大小或增加表空間文件
1.更改表空間的dbf數據文件分配空間大小
alter database datafile ‘...\system_01.dbf' autoextend on;
alter database datafile ‘...\system_01.dbf' resize 1024M;
2.1 為表空間新增一個數據文件(表空間滿32G不能擴展則增加表空間文件)
alter tablespace SYSTEM add datafile '/****' size 1000m autoextend on next 100m;
2.2 如果是temp臨時表新增表空間會報錯:
0RA-03217: 變更TEMPORARY TABLESPACE 無效的選項
解決方法: datafile改為tempfile
alter tablespace TEMP01 add tempfile'/****' size 1000m autoextend on next 100m;
針對temp臨時表空間使用率爆滿問題
臨時表空間主要用途是在數據庫進行排序運算、管理索引、訪問視圖等操作時提供臨時的運算空間,當運算完成之后系統會自動清理,但有些時候我們會遇到臨時段沒有被釋放,TEMP表空間幾乎滿使用率情況;
引起臨時表空間增大主要使用在以下幾種情況:
1、order by or group by (disc sort占主要部分);
2、索引的創建和重創建;
3、distinct操作;
4、union & intersect & minus sort-merge joins;
5、Analyze 操作;
6、有些異常也會引起TEMP的暴漲。
解決方法一:用上述方法給temp增加表空間文件
解決方法二:在服務器資源空間有限的情況下,重新建立新的臨時表空間替換當前的表空間
--1.查看當前的數據庫默認表空間:
select * from database_properties
where property_name='DEFAULT_TEMP_TABLESPACE';
--2.創建新的臨時表空間
create temporary tablespace TEMP01 tempfile
'/home/temp01.dbf' size 31G;
--3.更改默認臨時表空間
alter database default temporary tablespace TEMP01;
--4.刪除原來的臨時表空間
drop tablespace TEMP02 including contents and datafiles;
--如果刪除原來臨時表空間報錯ORA-60100:由于排序段,已阻止刪除表空間...
--(說明有語句正在使用原來的臨時表空間,需要將其kill掉再刪除,此語句多為排序的語句)
--查詢語句
Select se.username,se.sid,se.serial#,su.extents,su.blocks*to_number(rtrim(p.value))as Space,
tablespace,segtype,sql_text
from v$sort_usage su,v$parameter p,v$session se,v$sql s
where p.name='db_block_size' and su.session_addr=se.saddr and s.hash_value=su.sqlhash
and s.address=su.sqladdr
order by se.username,se.sid;
--刪除對應的'sid,serial#'
alter system kill session 'sid,serial#'
附:查看表空間是否具有自動擴展的能力
--查看表空間是否具有自動擴展的能力
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;
總結
原文鏈接:https://blog.csdn.net/qq_49122165/article/details/125252215
相關推薦
- 2022-05-23 Jenkins實現集群化管理以及流水線項目配置_nginx
- 2022-09-23 Go語言fmt.Sprintf格式化輸出的語法與實例_Golang
- 2024-02-28 UNI-APP,設置某個頁面橫屏后,恢復豎屏,返回再次進入其他頁面時,頁面內容放大錯亂
- 2022-08-12 Python?Pandas?中的數據結構詳解_python
- 2022-11-25 Python執行dos和Linux命令的方法詳解_python
- 2022-06-02 Go語言中定時任務庫Cron使用方法介紹_Golang
- 2022-07-07 Python?pluggy框架使用示例代碼_python
- 2022-10-18 pandas重復行刪除操作df.drop_duplicates和df.duplicated的區別_p
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支