tft每日頭條

 > 生活

 > 查詢臨時表空間文件路徑

查詢臨時表空間文件路徑

生活 更新时间:2025-04-20 07:24:22

查詢臨時表空間文件路徑?Oracle經常需要查數據庫臨時表空間大小,使用率,加表空間等,這裡總結臨時表空間相關的語句:,我來為大家科普一下關于查詢臨時表空間文件路徑?下面希望有你要的答案,我們一起來看看吧!

查詢臨時表空間文件路徑(關于臨時表空間問題總結)1

查詢臨時表空間文件路徑

Oracle經常需要查數據庫臨時表空間大小,使用率,加表空間等,這裡總結臨時表空間相關的語句:

0、查看實例的臨時表空間

SELECT * FROM dba_tablespaces t where t.CONTENTS='TEMPORARY'; SELECT PROPERTY_NAME, PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';

1、查詢臨時表空間路徑:

select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;

2、新增臨時表空間:

alter tablespace srmqy_temp add tempfile '/data/oradata/srmqy_temp01.dbf' size 64m autoextend on next 64m maxsize unlimited;

3、查詢臨時表空間使用情況:

select c.tablespace_name, to_char(c.bytes/1024/1024/1024,'99,999.999') total_gb, to_char( (c.bytes-d.bytes_used)/1024/1024/1024,'99,999.999') free_gb, to_char(d.bytes_used/1024/1024/1024,'99,999.999') use_gb, to_char(d.bytes_used*100/c.bytes,'99.99') || '%'use 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;

查看臨時表空間的使用情況

select a.tablespace_name, to_char(a.bytes / 1024 / 1024, '99,999.999') total_BYTES, to_char(b.bytes_used / 1024 / 1024, '99,999.999') use_bytes, to_char(b.bytes_used * 100 / a.bytes, '99.99') || '%' use from (select tablespace_name, sum(bytes) bytes from dba_temp_files group by tablespace_name) a, (select tablespace_name, sum(bytes_cached) bytes_used from v$temp_extent_pool group by tablespace_name) b where a.tablespace_name = b.tablespace_name

4、删除臨時表空間: 删除臨時表空間的一個數據文件:

SQL> alter database tempfile ‘/data/oradata/srmqy_temp01.dbf’ drop;

5、删除臨時表空間(徹底删除):

SQL> drop tablespace orcl_temp including contents and datafiles cascade constraints;

6、更改系統的默認臨時表空間:

--查詢默認臨時表空間 select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE'; --修改默認臨時表空間(所有用戶的默認臨時表空間都将切換為新的臨時表空間:) alter database default temporary tablespace temp1;

7、查看用戶的臨時表空間所屬

select username,temporary_tablespace,default_ from dba_users; --更改某一用戶的臨時表空間: alter user scott temporary tablespace temp;

8、删除臨時表空間

删除臨時表空間的一個數據文件: SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ drop; 删除臨時表空間(徹底删除): SQL> drop tablespace temp1 including contents and datafiles cascade constraints;

9、查看臨時表空間的使用情況(GV_$TEMP_SPACE_HEADER視圖必須在sys用戶下才能查詢)

GV_$TEMP_SPACE_HEADER視圖記錄了臨時表空間的使用大小與未使用的大小 dba_temp_files視圖的bytes字段記錄的是臨時表空間的總大小 臨時表空間是否自動擴展 select FILE_NAME, TABLESPACE_NAME, AUTOEXTENSIBLE,MAXBYTES/1024/1024 "MAXBYTES(M)", USER_BYTES/1024/1024 "USER_BYTES(M)" from dba_temp_files; select FILE_NAME "臨時表空間路徑", TABLESPACE_NAME "臨時表空間名", AUTOEXTENSIBLE "是否自動擴展",MAXBYTES/1024/1024 "表空間大小(M)", USER_BYTES/1024/1024 "表空間使用大小(M)" from dba_temp_files;

臨時表空間使用率 SELECT temp_used.tablespace_name, total - used as "Free", total as "Total", 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;

SELECT temp_used.tablespace_name as "臨時表空間名", total - used as "空閑空間(M)", total as "表空間大小(M)", round(nvl(total - used, 0) * 100 / total, 3) "空閑比率(%)" 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;

select h.tablespace_name tablespace_name,f.autoextensible, round(sum(nvl(p.bytes_used, 0)) / power(2, 30), 2) used_gb, round(sum(decode(f.autoextensible, 'YES', f.maxbytes, 'NO', f.bytes)) / power(2, 30), 2) max_gb from v$temp_space_header h, v$temp_extent_pool p, dba_temp_files f where p.file_id( ) = h.file_id and p.tablespace_name( ) = h.tablespace_name and f.file_id = h.file_id and f.tablespace_name = h.tablespace_name group by h.tablespace_name,f.autoextensible;

select FILE_NAME, TABLESPACE_NAME, AUTOEXTENSIBLE,MAXBYTES/1024/1024 "MAXBYTES(M)", USER_BYTES/1024/1024 "USER_BYTES(M)" from dba_temp_files;

select a.username,a.sql_id,a.SEGTYPE,b.BYTES_USED/1024/1024/1024||'G',b.BYTES_FREE/1024/1024/1024 from V$TEMPSEG_USAGE a join V$TEMP_SPACE_HEADER b on a.TABLESPACE=b.tablespace_name;

解釋: username 正在執行sql的用戶名 sql_id 正在執行的sql的的sql_id segtype 正在執行的SQL語句做的是什麼操作 BYTES_USED 正在執行sql語句使用的臨時表空間的大小 BYTES_FREE 剩餘多少臨時表空間

——設置輸出格式 sql>col file_name format a55     sql>set line 120 pagesize 2000

Oracle查看用戶及對應的表空間與臨時表空間

select username "用戶名稱",ACCOUNT_STATUS "用戶狀态",DEFAULT_TABLESPACE "表空間",TEMPORARY_TABLESPACE "臨時表空間" from dba_users order by 3,1;

删除數據庫數據操作: 1、解鎖當前用戶連接狀态:

alter user healmall account lock;commit;

2、删除指定用戶:

drop user healmall cascade; commit;

3、删除表空間:

drop tablespace healmall_tmp including contents and datafiles cascade constraint; drop tablespace healmall_data including contents and datafiles cascade constraint;

查看臨時表空間的數據文件的狀态

select file#,status,bytes/1024/1024 "MB",name from v$tempfile; select name,bytes/1024/1024 MB,status from v$datafile d union all select name,bytes/1024/1024 MB,status from v$tempfile;

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关生活资讯推荐

热门生活资讯推荐

网友关注

Copyright 2023-2025 - www.tftnews.com All Rights Reserved