Skip to content

Generate Tablespace Coalesce for Pattern (atsmerge.gen)

This generator script creates ALTER TABLESPACE COALESCE statements for tablespaces matching a pattern. Coalescing combines adjacent free extents to reduce fragmentation.

rem atsmerge.gen
rem
select '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)

The script prompts for:

  • &tablespace - Tablespace name pattern (use % for wildcard)
SELECT ANY DICTIONARY
-- OR --
SELECT ON DBA_TABLESPACES
-- Plus ALTER TABLESPACE privilege
alter tablespace USERS coalesce;
alter tablespace USERS_DATA coalesce;
alter tablespace USERS_INDEX coalesce;
  • 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

Coalesce User Tablespaces

@atsmerge.gen
-- Enter: USER% for tablespace

Coalesce Specific Tablespace

@atsmerge.gen
-- Enter: USERS for tablespace