Partitioning Tables  «Prev  Next»

Lesson 6Manipulating Partitions
Objective Rename, move, and coalesce Partitions

Manipulating Oracle Partitions

In Oracle 19c, you can rename, move, and coalesce partitions using specific SQL commands.
  1. Renaming a Partition

    You can rename a partition in an interval, range, list, or hash-partitioned table using the ALTER TABLE statement:


    ALTER TABLE table_name RENAME PARTITION old_partition_name 
    TO new_partition_name;
        

    Example:

    ALTER TABLE sales RENAME PARTITION sales_q1 TO sales_2024_q1;
    
  2. Moving a Partition

    Moving a partition is useful for changing tablespace storage or reorganizing data.

    ALTER TABLE table_name MOVE PARTITION partition_name TABLESPACE new_tablespace;
    

    Example:

    ALTER TABLE sales MOVE PARTITION sales_q1 TABLESPACE sales_archive;
        

    For index-organized tables, you must include the UPDATE INDEXES clause to maintain index integrity:

    ALTER TABLE sales MOVE PARTITION sales_q1 TABLESPACE sales_archive UPDATE INDEXES;
        
  3. Coalescing Partitions

    The ALTER TABLE ... COALESCE PARTITION command merges adjacent partitions in hash-partitioned tables.

    ALTER TABLE table_name COALESCE PARTITION;
        

Example:
ALTER TABLE sales COALESCE PARTITION;

This command removes an adjacent partition and redistributes its data to other partitions.
Additional Notes:
  • Renaming partitions is useful for maintenance, e.g., changing naming conventions.
  • Moving partitions is common in archival strategies, such as moving old data to a different tablespace.
  • Coalescing partitions applies only to hash partitions, reducing the total number of partitions while keeping data distribution efficient.




Steps To Manipulate Partitions

The code you create to
  1. move a partition to a different tablespace,
  2. merge two partitions into one, and
  3. rename a partition
should look something like this:
ALTER TABLE WHOLESALE_ORDER
MOVE PARTITION LOW_PART TABLESPACE LOW_PART_TS
/
ALTER TABLE WHOLESALE_ORDER
MERGE PARTITIONS
LOW_PART, MED_PART 
INTO PARTITION LOW1_PART
/
ALTER TABLE WHOLESALE_ORDER
RENAME PARTITION LOW1_PART TO LOWEST_PART
/

  • Moving Partitions Containing LOBs
    You can move a LOB partition into a different tablespace. This is useful if the tablespace is no longer large enough to hold the partition. To do so, use the
    ALTER
    TABLE ... MOVE PARTITION 
    
    clause.
    For example:
    ALTER TABLE current_table 
    MOVE PARTITION partition_name
    TABLESPACE destination_table_space
    LOB (column_name) 
    STORE AS (TABLESPACE current_tablespace);
    

The next lesson covers exchanging a partition with a table.

SEMrush Software