Generate Tablespace Coalesce for Pattern (atsmerge.gen)
What This Script Does
Section titled “What This Script Does”This generator script creates ALTER TABLESPACE COALESCE statements for tablespaces matching a pattern. Coalescing combines adjacent free extents to reduce fragmentation.
The Script
Section titled “The Script”rem atsmerge.genremselect 'alter tablespace ' || tablespace_name || ' coalesce;' from sys.dba_tablespaces where tablespace_name like upper('&tablespace') order by tablespace_name;
-- Basic usage@atsmerge.gen
-- When prompted, enter:-- tablespace: Tablespace name pattern (use % for wildcard)
Parameters
Section titled “Parameters”The script prompts for:
- &tablespace - Tablespace name pattern (use % for wildcard)
Required Privileges
Section titled “Required Privileges”SELECT ANY DICTIONARY-- OR --SELECT ON DBA_TABLESPACES-- Plus ALTER TABLESPACE privilege
Sample Output
Section titled “Sample Output”alter tablespace USERS coalesce;alter tablespace USERS_DATA coalesce;alter tablespace USERS_INDEX coalesce;
Key Features
Section titled “Key Features”- Pattern Matching: Filter tablespaces by name pattern
- Selective Coalescing: Target specific tablespaces only
- Alphabetical Order: Sorted output for organized execution
- Fragmentation Management: Combines free space efficiently
Common Use Cases
Section titled “Common Use Cases”Coalesce User Tablespaces
@atsmerge.gen-- Enter: USER% for tablespace
Coalesce Specific Tablespace
@atsmerge.gen-- Enter: USERS for tablespace
Related Scripts
Section titled “Related Scripts”- Tablespace Coalesce All - Coalesce all tablespaces
- Tablespace Growth Analysis - Monitor tablespace usage