tablespaces
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tablespaces [2016/12/05 11:30] – z0hpvk | tablespaces [2025/03/08 22:24] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Tablespaces ===== | ===== Tablespaces ===== | ||
| ==== Current Tablespace Usage ==== | ==== Current Tablespace Usage ==== | ||
| - | < | + | < |
| - | WITH Tablespace_Data as | + | |
| - | ( | + | COLUMN used_pct FORMAT A11 |
| - | SELECT tablespace_name, | + | COLUMN size_mb FORMAT 999,999 |
| - | ROUND(a.bytes/ | + | COLUMN free_mb FORMAT 999,999 |
| - | ROUND(a.maxbytes/ | + | COLUMN max_size_mb FORMAT 999,999 |
| - | ROUND(b.free_bytes/ | + | COLUMN max_free_mb FORMAT 999,999 |
| - | ROUND((a.maxbytes-a.bytes)/ | + | |
| - | 100 - ROUND(((b.free_bytes+a.growth)/a.maxbytes) * 100) AS pct_used | + | SELECT tablespace_name, |
| - | FROM (SELECT tablespace_name, | + | |
| - | GREATEST(bytes, | + | free_mb, |
| - | GREATEST(bytes, | + | max_size_mb, |
| - | FROM dba_data_files) a, | + | max_free_mb, |
| - | | + | TRUNC((max_free_mb/max_size_mb) * 100) AS free_pct |
| - | FROM dba_free_space GROUP BY file_id) b | + | FROM |
| - | WHERE a.file_id = b.file_id(+) | + | |
| - | ) | + | |
| - | SELECT tablespace_name, | + | |
| - | sum(size_mb) SIZE_MB, | + | b.max_size_mb, |
| - | sum(maxsize_mb) MAXSIZE_MB, | + | a.free_mb + (b.max_size_mb - b.size_mb) AS max_free_mb |
| - | sum(free_mb) FREE_MB, | + | FROM (SELECT tablespace_name, |
| - | sum(growth_mb) GROWTH_MB, | + | TRUNC(SUM(bytes)/1024/1024) AS free_mb |
| - | round((sum(size_mb)-sum(free_mb)) / sum(maxsize_mb)*100,2) PERCENTAGE_USED | + | FROM |
| - | | + | |
| - | group by tablespace_name;</ | + | |
| + | TRUNC(SUM(bytes)/1024/1024) AS size_mb, | ||
| + | TRUNC(SUM(GREATEST(bytes, | ||
| + | FROM | ||
| + | GROUP BY tablespace_name) b | ||
| + | | ||
| + | ) | ||
| + | ORDER BY tablespace_name; | ||
| + | </ | ||
| ==== Changing Undo Tablespace ==== | ==== Changing Undo Tablespace ==== | ||
| === Create New Undo Tablespace === | === Create New Undo Tablespace === | ||
| Line 59: | Line 68: | ||
| Use the following SQL to find the sessions ... | Use the following SQL to find the sessions ... | ||
| < | < | ||
| - | SELECT SID, SERIAL#, STATUS FROM V$SESSION WHERE SERIAL# | + | SELECT SID, SERIAL#, STATUS FROM V$SESSION WHERE SERIAL# |
| < | < | ||
| < | < | ||
| < | < | ||
| + | To discover what the default temporary tablespace is ... | ||
| + | < | ||
| + | |||
| + | ==== Data File Management ==== | ||
| + | < | ||
| + | ALTER TABLESPACE USERS ADD DATAFILE '/ | ||
| + | ALTER DATABASE DATAFILE '/ | ||
| + | </ | ||
| + | |||
| + | ==== Default Tablespaces ==== | ||
| + | <code SQL> | ||
| + | SELECT * FROM database_properties WHERE property_name like ' | ||
| + | </ | ||
| + | |||
| + | ==== Resize Data Files ==== | ||
| + | <code SQL> | ||
| + | -- Report on which data files can be shrunk | ||
| + | set verify off pagesize 50 linesize 120 | ||
| + | column file_name format a60 word_wrapped | ||
| + | column smallest format 999,990 heading " | ||
| + | column currsize format 999,990 heading " | ||
| + | column savings | ||
| + | break on report | ||
| + | compute sum of savings on report | ||
| + | column value new_val blksize | ||
| + | select file_name, | ||
| + | ceil( (nvl(hwm, | ||
| + | ceil( blocks*&& | ||
| + | ceil( blocks*&& | ||
| + | ceil( (nvl(hwm, | ||
| + | from dba_data_files a, | ||
| + | ( select file_id, max(block_id+blocks-1) hwm | ||
| + | from dba_extents | ||
| + | group by file_id ) b | ||
| + | where a.file_id = b.file_id(+) | ||
| + | order by savings desc; | ||
| + | </ | ||
| + | |||
tablespaces.1480937441.txt.gz · Last modified: (external edit)
