Dba tablespaces 8

De wiki.nexiat.fr
Aller à la navigation Aller à la recherche
Fiche express
Type Script SQL*Plus de diagnostic
Domaine Administration
Voir aussi Dba tablespaces · Dba tablespaces 7 · Dba top segments

Dba tablespaces 8 est la variante intermédiaire du rapport de tablespaces, conçue pour Oracle8i et plus récent. Comme Dba tablespaces, elle sait remonter les vrais tablespaces TEMPORARY basés sur des tempfiles, mais elle n'affiche pas la colonne de gestion des segments (segment_space_management), notion introduite plus tard et exploitée uniquement par la version courante du script.

Script

-- Rapport sur les tablespaces (taille, utilisation, % occupé)
-- Compatible Oracle8i et plus récent

SET TERMOUT OFF
COLUMN current_instance NEW_VALUE current_instance NOPRINT
SELECT rpad(instance_name, 17) current_instance FROM v$instance;
SET TERMOUT ON

PROMPT
PROMPT +------------------------------------------------------------------------+
PROMPT | Report   : Tablespaces                                                 |
PROMPT | Instance : &current_instance                                           |
PROMPT +------------------------------------------------------------------------+

SET ECHO        OFF
SET FEEDBACK    6
SET HEADING     ON
SET LINESIZE    180
SET PAGESIZE    50000
SET TIMING      OFF
SET TRIMOUT     ON
SET TRIMSPOOL   ON
SET VERIFY      OFF

CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES

COLUMN status     FORMAT a9                 HEADING 'Status'
COLUMN name       FORMAT a30                HEADING 'Tablespace Name'
COLUMN type       FORMAT a15                HEADING 'TS Type'
COLUMN extent_mgt FORMAT a11                HEADING 'Extent Mgt.'
COLUMN ts_size    FORMAT 9,999,999,999,999  HEADING 'Tablespace Size'
COLUMN used       FORMAT 9,999,999,999,999  HEADING 'Used (in bytes)'
COLUMN free       FORMAT 9,999,999,999,999  HEADING 'Free (in bytes)'
COLUMN pct_used   FORMAT 999                HEADING 'Pct. Used'

BREAK ON report

COMPUTE sum OF ts_size  ON report
COMPUTE sum OF used     ON report
COMPUTE sum OF free     ON report
COMPUTE avg OF pct_used ON report

SELECT
    d.status                                            status
  , d.tablespace_name                                   name
  , d.contents                                          type
  , d.extent_management                                 extent_mgt
  , NVL(a.bytes, 0)                                     ts_size
  , NVL(a.bytes - NVL(f.bytes, 0), 0)                   used
  , NVL(f.bytes, 0)                                     free
  , NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0) pct_used
FROM
    sys.dba_tablespaces d
  , ( 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
    ) f
WHERE
      d.tablespace_name = a.tablespace_name(+)
  AND d.tablespace_name = f.tablespace_name(+)
  AND NOT (
        d.extent_management LIKE 'LOCAL'
    AND d.contents           LIKE 'TEMPORARY'
      )
UNION ALL
SELECT
    d.status                          status
  , d.tablespace_name                 name
  , d.contents                        type
  , d.extent_management               extent_mgt
  , NVL(a.bytes, 0)                   ts_size
  , NVL(t.bytes, 0)                   used
  , NVL(a.bytes - NVL(t.bytes, 0), 0) free
  , NVL(t.bytes / a.bytes * 100, 0)   pct_used
FROM
    sys.dba_tablespaces d
  , ( SELECT tablespace_name, SUM(bytes) bytes
      FROM dba_temp_files
      GROUP BY tablespace_name
    ) a
  , ( SELECT tablespace_name, SUM(bytes_cached) bytes
      FROM v$temp_extent_pool
      GROUP BY tablespace_name
    ) t
WHERE
      d.tablespace_name = a.tablespace_name(+)
  AND d.tablespace_name = t.tablespace_name(+)
  AND d.extent_management LIKE 'LOCAL'
  AND d.contents           LIKE 'TEMPORARY'
ORDER BY
    2
/

Corrections apportées par rapport au script d'origine : l'alias de colonne extent_mg (tronqué, faute de frappe) dans la seconde requête a été corrigé en extent_mgt pour matcher la première branche de l'UNION ALL, et un ORDER BY explicite a été ajouté (absent dans la version source, ce qui laissait l'ordre d'affichage indéterminé).

Voir aussi