0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Oracle表領域情報を取得するSQL

Last updated at Posted at 2025-02-20

Oracle Database 19c用
BIGFILEに対応し、自動拡張にも対応したものになっております。
表領域個別ブロックサイズにも対応したものになっております。

警告
SMALLFILEで自動拡張ありとなしのファイルが混在している場合には、正しく表示されません。

主な列の説明。

列名 説明
tsname 表領域名
bigfile BIGFILE表領域なら Y、SMALLFILE表領域なら N
tsmax 表領域最大サイズ(MB) データファイルが自動拡張の時は、自動拡張の最大サイズの合計。
autoextensible 自動拡張の有無
tssize データファイルの合計サイズ(MB)
tsused 表領域の使用サイズ(MB)
tsfree 表領域の未使用サイズ(MB)
tsusedpct 表領域の使用率。計算式は、tsused/tsmax

SQL

set pages 150 lin 150
col tsname format a25
col tsmax format 999,999,999.99
col tssize format 999,999,999.99
col tsused format 999,999,999.99
col tsfree format 999,999,999.99
col tsusedpct format 990.99
WITH
 total_free_space AS (
 SELECT tablespace_name , SUM(bytes) AS bytes
 FROM dba_free_space
 GROUP BY tablespace_name
 ),
 ts_file_spec AS (
 select tablespace_name, sum(bytes)/1024/1024 AS bytes_mb, autoextensible
 from dba_data_files
 group by tablespace_name, autoextensible
 )
SELECT
 usage.tablespace_name AS tsname
 , tblsp.bigfile
 , usage.tablespace_size * tblsp.block_size/1024/1024 AS tsmax
 , spec.autoextensible
 , spec.bytes_mb as tssize
 , usage.used_space * tblsp.block_size/1024/1024 AS tsused
 , (usage.tablespace_size - usage.used_space) * tblsp.block_size /1024/1024 AS tsfree
 , usage.used_percent AS tsusedpct
FROM
 dba_tablespace_usage_metrics usage
 INNER JOIN dba_tablespaces tblsp ON usage.tablespace_name = tblsp.tablespace_name
 INNER JOIN total_free_space free ON usage.tablespace_name = free.tablespace_name
 INNER JOIN ts_file_spec spec ON usage.tablespace_name = spec.tablespace_name
ORDER BY
 usage.tablespace_name;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?