top of page

Partitioning a Live Table Online and Compressing Its History on Exadata in Oracle Database@Azure

OmerNarman
Nov 8
7 min read

Most large tables start small. The orders table was created years ago without partitioning, and now it holds every order since the business started. Queries for last month read far more than they need, purges take a weekend, and the backup of a table where 90 percent of the rows never change is repeated every week.


Since Oracle Database 12.2, a non-partitioned table can be converted to a partitioned one with a single ALTER TABLE statement, online, while the application keeps inserting and updating rows. On Exadata, the history partitions can then be moved to Hybrid Columnar Compression, also online. This post does both on a production table in Exadata Database Service in Oracle Database@Azure, and shows how to check every stage.



The Use Case

The order-entry application in Azure writes to SALES.ORDERS around the clock. The table holds 2.1 billion rows from January 2021 to today and takes 900 GB. Monthly reports scan the whole table, and the plan to drop data older than five years has never been carried out because a DELETE of that size is too risky. The goal is monthly partitions, created automatically, with older data compressed, and no maintenance window.


Environment used in this runbook


  • Service: Exadata Database Service on Dedicated Infrastructure in Oracle Database@Azure

  • Database: Oracle Database 19c (19.24), PDB SALESPDB, two-node RAC

  • Table: SALES.ORDERS, 2.1 billion rows, 900 GB, partition key ORDER_DATE

  • Indexes: primary key on ORDER_ID, non-unique indexes on ORDER_DATE and CUSTOMER_ID

  • Licence: Partitioning is an extra-cost option of Enterprise Edition, and an online move of a partition to a compressed format is part of the Advanced Compression option; both are included in the licence-included Exadata Database Service, but must be licensed separately with Bring Your Own License. Hybrid Columnar Compression itself requires Exadata storage



Why Convert Online

  • One statement. ALTER TABLE ... MODIFY PARTITION BY ... ONLINE replaces the older routes through DBMS_REDEFINITION or partition exchange.

  • The application keeps running. DML continues during the conversion; changes made meanwhile are applied to the new partitioned segment before it takes over.

  • Indexes come along. The UPDATE INDEXES clause says which indexes become local and which stay global, and they are maintained during the conversion.

  • Interval partitioning creates new partitions on its own. A partition for each new month appears when the first row for that month is inserted.



Step 1: Measure the Table and Its Indexes

Start with the size of the table and its indexes. The online conversion builds a complete new copy, so the tablespace needs about as much free space again as the table and its indexes use today.


SQL

-- Connected to SALESPDB as a DBA

COLUMN segment_name FORMAT A16

COLUMN segment_type FORMAT A10

SELECT segment_name, segment_type, ROUND(SUM(bytes)/1024/1024/1024) AS gb

FROM dba_segments

WHERE owner = 'SALES'

AND segment_name IN ('ORDERS', 'ORDERS_PK', 'ORDERS_DATE_IX', 'ORDERS_CUST_IX')

GROUP BY segment_name, segment_type

ORDER BY gb DESC;

Expected output

SEGMENT_NAME     SEGMENT_TY         GB
---------------- ---------- ----------
ORDERS           TABLE             900
ORDERS_PK        INDEX              62
ORDERS_CUST_IX   INDEX              58
ORDERS_DATE_IX   INDEX              55

What to expect: About 1.1 TB in total, so the tablespace must have at least that much free space, or be able to autoextend that far. On Exadata Database Service, check the free space in the DATA disk group as well; a conversion that runs out of space fails and has to start again.



Step 2: Check the Prerequisites

Confirm that the table is not already partitioned and has no index types that the online conversion cannot handle, such as domain indexes, and list the indexes with their columns.


SQL

COLUMN index_name FORMAT A16

COLUMN index_type FORMAT A10

COLUMN column_name FORMAT A12

SELECT i.index_name, i.index_type, i.uniqueness, c.column_name

FROM dba_indexes i

JOIN dba_ind_columns c

ON c.index_owner = i.owner AND c.index_name = i.index_name

WHERE i.table_owner = 'SALES' AND i.table_name = 'ORDERS'

ORDER BY i.index_name, c.column_position;

SELECT partitioned FROM dba_tables WHERE owner = 'SALES' AND table_name = 'ORDERS';

Expected output

INDEX_NAME       INDEX_TYPE UNIQUENES COLUMN_NAME
---------------- ---------- --------- ------------
ORDERS_CUST_IX   NORMAL     NONUNIQUE CUSTOMER_ID
ORDERS_DATE_IX   NORMAL     NONUNIQUE ORDER_DATE
ORDERS_PK        NORMAL     UNIQUE    ORDER_ID

PAR
---
NO

What to expect: Three normal B-tree indexes and a table that is not partitioned. The primary key does not contain ORDER_DATE, so it cannot be a local index and must stay global. The other two can become local, which makes later partition maintenance much simpler.



Step 3: Convert the Table Online

Run the conversion during a quiet period, such as the night, but without stopping the application. The first partition holds everything before 2025; from there, interval partitioning creates one partition per month.


SQL

ALTER TABLE sales.orders

MODIFY PARTITION BY RANGE (order_date)

INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))

( PARTITION p_history VALUES LESS THAN (DATE '2025-01-01') )

ONLINE

UPDATE INDEXES

( orders_date_ix LOCAL,

orders_cust_ix LOCAL,

orders_pk GLOBAL );

Expected output

Table altered.

Elapsed: 01:47:12.38

What this does: It builds a new interval-partitioned segment from the existing rows, keeps the indexes in step, applies the DML that happened in the meantime, and switches over at the end with a short lock. ORDERS_DATE_IX and ORDERS_CUST_IX become local indexes; the primary key stays a global, non-partitioned index. Expect the elapsed time to depend mostly on table size and the I/O capacity of the Exadata storage cells.


Tip: Run the statement from a session that will not be cut off, for example in a screen or tmux session on the database server, or as a scheduler job. If the session is killed, the conversion is rolled back and has to start again from the beginning.


Step 4: Check the Partitions

Gather statistics, then look at the partitions that were created. With incremental statistics, later gathers only read the partitions that changed.


SQL

BEGIN

DBMS_STATS.SET_TABLE_PREFS('SALES', 'ORDERS', 'INCREMENTAL', 'TRUE');

DBMS_STATS.GATHER_TABLE_STATS('SALES', 'ORDERS', degree => 16);

END;

/

COLUMN partition_name FORMAT A10

SELECT partition_position AS pos, partition_name, num_rows

FROM dba_tab_partitions

WHERE table_owner = 'SALES' AND table_name = 'ORDERS'

AND (partition_position <= 3 OR partition_position >= 23)

ORDER BY partition_position;

Expected output

PL/SQL procedure successfully completed.

       POS PARTITION_   NUM_ROWS
---------- ---------- ----------
         1 P_HISTORY  1590412877
         2 SYS_P4101    21544310
         3 SYS_P4102    20871965
        23 SYS_P4122    23905114
        24 SYS_P4123     5482260

What to expect: P_HISTORY with the rows from before 2025, then one partition per month from January 2025. Partition 24 is November 2026, still filling up. The SYS_P names are generated by the database; rename them with ALTER TABLE ... RENAME PARTITION if your scripts refer to partitions by name.



Step 5: Check the Indexes

Confirm that the local indexes are partitioned like the table and that every index is usable.


SQL

COLUMN index_name FORMAT A16

COLUMN locality FORMAT A8

SELECT i.index_name, p.locality, i.status, i.partitioned

FROM dba_indexes i

LEFT JOIN dba_part_indexes p

ON p.owner = i.owner AND p.index_name = i.index_name

WHERE i.table_owner = 'SALES' AND i.table_name = 'ORDERS'

ORDER BY i.index_name;

Expected output

INDEX_NAME       LOCALITY STATUS   PAR
---------------- -------- -------- ---
ORDERS_CUST_IX   LOCAL    N/A      YES
ORDERS_DATE_IX   LOCAL    N/A      YES
ORDERS_PK                 VALID    NO

What to expect: The two local indexes show N/A at index level, because their status is held per partition, and the primary key is VALID. To be thorough, check that no row in DBA_IND_PARTITIONS for these indexes has the status UNUSABLE.



Step 6: Confirm Partition Pruning

Partitioning pays off when queries read only the partitions they need. Check the plan of a typical monthly report.


SQL

EXPLAIN PLAN FOR

SELECT customer_id, SUM(amount)

FROM sales.orders

WHERE order_date >= DATE '2026-10-01'

AND order_date < DATE '2026-11-01'

GROUP BY customer_id;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY(format => 'BASIC +PARTITION'));

Expected output

---------------------------------------------------------------------
| Id  | Operation                          | Name   | Pstart| Pstop |
---------------------------------------------------------------------
|   0 | SELECT STATEMENT                   |        |       |       |
|   1 |  HASH GROUP BY                     |        |       |       |
|   2 |   PARTITION RANGE SINGLE           |        |    23 |    23 |
|   3 |    TABLE ACCESS STORAGE FULL       | ORDERS |    23 |    23 |
---------------------------------------------------------------------

What to expect: PARTITION RANGE SINGLE with Pstart and Pstop both 23: the report reads one month instead of the whole table. TABLE ACCESS STORAGE FULL shows that the scan is offloaded to the Exadata storage cells, which now scan about 4 percent of the data they scanned before.



Step 7: Compress the History Partition Online

The rows in P_HISTORY are no longer updated. Move the partition into Hybrid Columnar Compression, online, so that the application can still read and, if needed, change the old rows.


SQL

ALTER TABLE sales.orders

MOVE PARTITION p_history

COLUMN STORE COMPRESS FOR QUERY HIGH

ONLINE

UPDATE INDEXES;

Expected output

Table altered.

Elapsed: 00:52:40.11

What this does: It rewrites P_HISTORY in HCC QUERY HIGH format, which stores data by column within compression units and usually compresses order data many times over. The ONLINE keyword lets DML continue during the move, and UPDATE INDEXES keeps the global primary key and the local index partitions usable. Rows that are updated later are stored with lighter compression, so keep HCC for data that really is read-mostly.



Step 8: Measure the Space Saved

Compare the size of the compressed partition with the uncompressed monthly partitions, and check the compression setting of each partition.


SQL

COLUMN partition_name FORMAT A10

COLUMN compress_for FORMAT A12

SELECT p.partition_name, p.compress_for,

ROUND(s.bytes/1024/1024/1024) AS gb

FROM dba_tab_partitions p

JOIN dba_segments s

ON s.owner = p.table_owner AND s.segment_name = p.table_name

AND s.partition_name = p.partition_name

WHERE p.table_owner = 'SALES' AND p.table_name = 'ORDERS'

AND p.partition_position IN (1, 2, 3)

ORDER BY p.partition_position;

Expected output

PARTITION_ COMPRESS_FOR         GB
---------- ------------ ----------
P_HISTORY  QUERY HIGH           71
SYS_P4101                        9
SYS_P4102                        9

What to expect: P_HISTORY shrinks from roughly 680 GB to 71 GB, and the whole table from 900 GB to under 300 GB. The space freed inside the tablespace is available for new partitions straight away; shrinking the datafiles themselves is a separate step if you need the space back at the disk group level.


Tip: When a month has been closed for a year or so, move its partition to HCC in the same way. A small scheduler job that compresses partitions older than twelve months keeps the table at its new size without anyone remembering to do it.


Step 9: Plan the Purge

With partitions, removing old data is no longer a weekend-long DELETE. When the business agrees on a retention period, dropping a month is a quick dictionary operation. Check the oldest partitions first.


SQL

COLUMN partition_name FORMAT A10

SELECT partition_name, num_rows

FROM dba_tab_partitions

WHERE table_owner = 'SALES' AND table_name = 'ORDERS'

AND partition_position <= 2

ORDER BY partition_position;

-- When the retention rule allows it, for example:

-- ALTER TABLE sales.orders DROP PARTITION sys_p4101 UPDATE INDEXES;

Expected output

PARTITION_   NUM_ROWS
---------- ----------
P_HISTORY  1590412877
SYS_P4101    21544310

What to expect: The candidates for the next purge. Splitting P_HISTORY into yearly partitions, with ALTER TABLE ... SPLIT PARTITION ... ONLINE in 19c, makes it possible to drop whole years later. Always keep UPDATE INDEXES on partition maintenance so that the global primary key stays usable.



Summary

A table that has outgrown its design can be partitioned without downtime. Measure the table and its indexes and make sure there is space for a second copy, check that no index stops the online conversion, and run ALTER TABLE ... MODIFY PARTITION BY RANGE ... INTERVAL ... ONLINE UPDATE INDEXES, choosing which indexes become local. Gather incremental statistics, check partitions, index status and partition pruning, then move the history partition to Hybrid Columnar Compression online and measure the space saved. On Exadata Database Service in Oracle Database@Azure, Partitioning and Advanced Compression are included in the licence-included model, but must be licensed separately when you bring your own licences.

Recent Posts

See All

Comments


bottom of page