Tablespace Definitions (dtspace.sql)
What This Script Does
Section titled “What This Script Does”This script provides a comprehensive view of tablespace configuration including extent management, space allocation, and segment management settings. It displays only non-default values for cleaner output, helping DBAs understand tablespace architecture and identify configuration differences across tablespaces.
Script
Section titled “Script”rem dtspace.sqlremset linesize 132remttitle 'Tablespace Definitions'remclear breakremcol contents format a9 heading 'CONTENTS'col status format a6 heading 'STATUS'col logging format a3 heading 'LOG'col tablespace_name format a25 heading 'TABLESPACE'col initial_extent format 999,999 heading 'INITIAL|EXTENT|(K)'col next_extent format 999,999 heading 'NEXT|EXTENT|(K)'col min_extents format 99 heading 'MIN|EXT'col max_extents format 999999 heading 'MAX|EXT'col pct_increase format 999 heading 'PCT|INC'col EXTENT_MANAGEMENT format a5 heading 'EXT|MGMT'col ALLOCATION_TYPE format a7 heading 'ALLOC'col SEGMENT_SPACE_MANAGEMENT format a6 heading 'SEG|MGMT'select decode( contents, 'PERMANENT', null, contents ) contents, decode( status, 'ONLINE', null, status ) status, decode(logging, 'NOLOGGING', 'NO', NULL) logging, decode(extent_management, 'DICTIONARY', null, extent_management) extent_management, decode(allocation_type, 'USER', null, allocation_type) allocation_type, segment_space_management, tablespace_name, initial_extent/1024 initial_extent, next_extent/1024 next_extent, min_extents, max_extents, pct_increase, block_size from sys.dba_tablespaces where tablespace_name like nvl(upper('&tablespace'), '%') order by tablespace_name;
-- Run the script in SQL*Plus or SQLcl@dtspace.sql
-- When prompted, enter:-- tablespace: Tablespace name pattern (% for all)
-- ExamplesEnter value for tablespace: %-- Or filter specific tablespaceEnter value for tablespace: USERS
Parameters
Section titled “Parameters”- &tablespace: Tablespace name pattern (use % for all tablespaces)
Required Privileges
Section titled “Required Privileges”- SELECT on SYS.DBA_TABLESPACES
- Typically requires DBA role or SELECT_CATALOG_ROLE
Sample Output
Section titled “Sample Output”Tablespace Definitions
CONTENTS STATUS LOG EXT ALLOC SEG TABLESPACE INITIAL NEXT MIN MAX PCT BLOCK_SIZE MGMT MGMT EXTENT EXTENT EXT EXT INC--------- ------ --- ----- ------- ------ ------------------------- ------- ------- --- ------ --- ---------- LOCAL SYSTEM AUTO SYSAUX 64 512 1 2147 0 8192 LOCAL SYSTEM AUTO SYSTEM 64 512 1 2147 0 8192TEMPORARY NO LOCAL UNIFORM MANUAL TEMP 1024 1024 1 4095 0 8192UNDO NO LOCAL SYSTEM AUTO UNDOTBS1 64 512 1 2147 0 8192 LOCAL SYSTEM AUTO USERS 64 512 1 2147 0 8192
Key Output Columns
Section titled “Key Output Columns”- CONTENTS: Tablespace content type (TEMPORARY, UNDO, or blank for PERMANENT)
- STATUS: Status if not ONLINE (OFFLINE, READ ONLY)
- LOG: Logging mode (NO for NOLOGGING, blank for LOGGING)
- EXT MGMT: Extent management (LOCAL or blank for DICTIONARY)
- ALLOC: Allocation type (SYSTEM, UNIFORM, or blank for USER)
- SEG MGMT: Segment space management (AUTO, MANUAL)
- TABLESPACE: Tablespace name
- INITIAL EXTENT: Initial extent size in KB
- NEXT EXTENT: Next extent size in KB
- MIN EXT: Minimum extents
- MAX EXT: Maximum extents (2147 = UNLIMITED)
- PCT INC: Percent increase for next extent
- BLOCK_SIZE: Block size in bytes
Understanding Tablespace Configuration
Section titled “Understanding Tablespace Configuration”Extent Management Types
Section titled “Extent Management Types”- LOCAL: Locally managed tablespaces (recommended)
- DICTIONARY: Dictionary-managed (deprecated)
Allocation Types
Section titled “Allocation Types”- SYSTEM: Oracle determines extent sizes automatically
- UNIFORM: All extents are same size
- USER: User-specified extent sizes (with DICTIONARY management)
Segment Space Management
Section titled “Segment Space Management”- AUTO: ASSM (Automatic Segment Space Management) - recommended
- MANUAL: Manual segment space management with freelists
Content Types
Section titled “Content Types”- PERMANENT: Regular data tablespaces
- TEMPORARY: Temporary segments for sorting
- UNDO: Undo/rollback segments
Performance Analysis
Section titled “Performance Analysis”Optimal Configuration Indicators
Section titled “Optimal Configuration Indicators”- LOCAL extent management: Better performance than DICTIONARY
- AUTO segment space management: Reduces contention
- SYSTEM allocation: Automatic extent sizing
- Appropriate block sizes: Match workload characteristics
Configuration Issues
Section titled “Configuration Issues”- DICTIONARY management: Should be migrated to LOCAL
- MANUAL segment management: Consider migrating to AUTO
- PCT_INCREASE > 0: Can cause fragmentation
- Small INITIAL_EXTENT: May cause excessive extents
Common Use Cases
Section titled “Common Use Cases”Configuration Audit
Section titled “Configuration Audit”-- Review all tablespace configurations@dtspace.sql-- Enter % to see all tablespaces-- Look for non-optimal settings
Migration Planning
Section titled “Migration Planning”-- Identify tablespaces needing migration@dtspace.sql-- Focus on DICTIONARY managed tablespaces-- Plan LOCAL management migration
Performance Tuning
Section titled “Performance Tuning”-- Analyze extent and block configurations@dtspace.sql-- Review extent sizes and allocation types-- Optimize for workload patterns
Troubleshooting Configuration Issues
Section titled “Troubleshooting Configuration Issues”Dictionary-Managed Tablespaces
Section titled “Dictionary-Managed Tablespaces”-
Migration to LOCAL:
-- Migrate to locally managedEXEC DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_TO_LOCAL('tablespace_name'); -
Verification:
SELECT tablespace_name, extent_managementFROM dba_tablespacesWHERE extent_management = 'DICTIONARY';
Manual Segment Space Management
Section titled “Manual Segment Space Management”- Migration to ASSM:
-- Cannot migrate directly - requires rebuild-- Create new tablespace with AUTOCREATE TABLESPACE new_tsDATAFILE '/path/to/datafile.dbf' SIZE 100MEXTENT MANAGEMENT LOCALSEGMENT SPACE MANAGEMENT AUTO;
Fragmentation Issues
Section titled “Fragmentation Issues”-
Check for fragmentation:
SELECT tablespace_name, COUNT(*) extent_count,MAX(bytes)/1024/1024 max_extent_mbFROM dba_free_spaceGROUP BY tablespace_nameHAVING COUNT(*) > 100; -
Resolve with uniform allocation:
CREATE TABLESPACE uniform_tsDATAFILE '/path/to/file.dbf' SIZE 100MEXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;
Advanced Analysis
Section titled “Advanced Analysis”Tablespace Comparison
Section titled “Tablespace Comparison”-- Compare configurations across tablespacesSELECT extent_management, allocation_type, segment_space_management, COUNT(*) tablespace_countFROM dba_tablespacesGROUP BY extent_management, allocation_type, segment_space_managementORDER BY tablespace_count DESC;
Block Size Analysis
Section titled “Block Size Analysis”-- Analyze block size distributionSELECT block_size, COUNT(*) tablespace_count, LISTAGG(tablespace_name, ', ') WITHIN GROUP (ORDER BY tablespace_name) tablespacesFROM dba_tablespacesGROUP BY block_sizeORDER BY block_size;
Extent Size Recommendations
Section titled “Extent Size Recommendations”-- Calculate optimal extent sizes based on object sizesSELECT tablespace_name, ROUND(AVG(bytes)/1024/1024, 2) avg_segment_size_mb, CASE WHEN AVG(bytes)/1024/1024 < 100 THEN '1M UNIFORM' WHEN AVG(bytes)/1024/1024 < 1000 THEN '8M UNIFORM' ELSE 'SYSTEM ALLOCATION' END recommended_allocationFROM dba_segmentsWHERE tablespace_name NOT IN ('SYSTEM', 'SYSAUX')GROUP BY tablespace_name;
Related Scripts
Section titled “Related Scripts”- Tablespace Space Usage (ddbspace.sql) - Space utilization analysis
- Database Files (dfile.sql) - Datafile information
- Segment Analysis (dsegment.sql) - Object space usage
- Database Information (vdb.sql) - Overall database configuration