Partitioning in Practice with IvorySQL 5.6
Testing partition creation, splitting and archiving in IvorySQL 5.6, with planning measurements for 100 and 1,000 partitions and practical notes on constraints and transactions.
Wu Liang
We rely heavily on partitioning in our system for two straightforward reasons: large tables need to be split up, and historical data needs to be taken offline.
Once a single table grows to tens or hundreds of gigabytes, queries, vacuuming, and index rebuilds all compete over the same object. Every operation involves the whole table. With time-based RANGE partitions, queries that include a date only open the relevant partitions, immediately reducing the amount scanned. Removing historical data no longer requires DELETE: detach the old partition, then move it into the archive. Maintenance can also be spread out: work on this month's partition today and last month's tomorrow, without reserving a maintenance window for hundreds of gigabytes at once.
The trade-off is more operational work. Creating, detaching, and changing partitions becomes a monthly routine, and rough scripts can easily cause trouble. When I started evaluating IvorySQL, my first question was whether its partitioning could support our existing approach.
What this article covers
If you are evaluating a migration from Oracle partitioned tables, you want to know how much DDL needs changing. If the original partition granularity was wrong and you now want to split half-year partitions into quarters, or merge monthly partitions into quarters, the question is whether you can do it without interrupting service. And if the partition count has grown from dozens to hundreds, with Planning Time rising from fractions of a millisecond to several milliseconds, you probably want to know what another tenfold increase would mean.
Environment
I used the all-in-one 5.6 RPM from GitHub Releases (IvorySQL-5.6-74c405c-20261016.x86_64.rpm, approximately 190 MB), installed under /usr/ivory-5/, with no additional dependencies to resolve. Version 5.6 is the GA release published on September 18, based on PostgreSQL 18.6. Initialize it with:
initdb -D $PGDATA -m oracle
The default value of -m is already oracle. After startup, both 5432 and 1521 listen for connections. This is IvorySQL's dual-parser architecture: port 1521 uses the Oracle parser, while port 5432 uses the PG parser. One detail can be confusing: checking compatibility mode on port 5432 reports pg:
SHOW ivorysql.compatible_mode;
ivorysql.compatible_mode
--------------------------
pg
(1 row)
Time: 0.041 ms
At first glance, it looks as though Oracle compatibility is disabled. In fact, each parser serves its own port. To check which parser the current session uses, enter \parser:
PG parser.
Check the version as well:
SELECT version();
version
---------------------------------------------------------------------------------------------
PostgreSQL 18.6 (IvorySQL 5.6) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 10.2.0, 64-bit
(1 row)
Time: 0.318 ms
Creating tables
CREATE TABLE sales (
sale_id NUMBER,
sale_date DATE,
region VARCHAR2(20),
amount NUMBER(12,2)
) PARTITION BY RANGE (sale_date);
CREATE TABLE sales_2026h1 PARTITION OF sales
FOR VALUES FROM (DATE '2026-01-01') TO (DATE '2026-07-01');
CREATE TABLE
Time: 1.727 ms
CREATE TABLE
Time: 1.916 ms
NUMBER, VARCHAR2, and DATE worked without changes, and DATE retained Oracle semantics, with precision down to seconds. The partition clause uses PostgreSQL's FOR VALUES FROM ... TO ...: the lower bound is inclusive and the upper bound exclusive. This agrees with Oracle's VALUES LESS THAN in excluding the upper endpoint, but the syntax differs, and mixing them up is easy. A classic example is a row timestamped at midnight on July 1: does it belong to the first or second half of the year? Make the boundary explicit in the script rather than relying on memory. I generate all boundary dates in scripts instead of typing them into SQL by hand.
Monthly partition creation is best handled with a template. A single DO block can create a thousand monthly partitions:
DO $$
DECLARE i int;
BEGIN
FOR i IN 0..999 LOOP
EXECUTE format(
'CREATE TABLE m_%s PARTITION OF m FOR VALUES FROM (%L) TO (%L)',
to_char(DATE '2026-01-01' + (i || ' month')::interval, 'YYYYMM'),
DATE '2026-01-01' + (i || ' month')::interval,
DATE '2026-01-01' + ((i + 1) || ' month')::interval);
END LOOP;
END $$;
DO
Time: 1397.802 ms (00:01.398)
Splitting a half-year partition into quarters
A realistic requirement: a table has been running for a while, and a half-year partition now feels too coarse. You want quarters instead. On 5.6, this takes four steps. There is some setup, but in this test the actual structural switch for 240,000 rows took less than 15 ms, with no visible interruption to the application.
First, count the rows so that you can reconcile them afterward:
SELECT count(*) AS before_split FROM sales;
before_split
--------------
240002
(1 row)
Time: 10.093 ms
Step one: create shadow tables and backfill them:
CREATE TABLE sales_q1_new (LIKE sales INCLUDING DEFAULTS INCLUDING CONSTRAINTS);
CREATE TABLE sales_q2_new (LIKE sales INCLUDING DEFAULTS INCLUDING CONSTRAINTS);
INSERT INTO sales_q1_new SELECT * FROM sales_2026h1 WHERE sale_date < DATE '2026-04-01';
INSERT INTO sales_q2_new SELECT * FROM sales_2026h1 WHERE sale_date >= DATE '2026-04-01';
CREATE TABLE
Time: 1.338 ms
CREATE TABLE
Time: 2.751 ms
INSERT 0 119340
Time: 90.535 ms
INSERT 0 120662
Time: 74.503 ms
This step only reads the old partition and writes new tables, leaving the application unaffected. If something goes wrong, simply drop the shadow tables. It can therefore be done during the day. Splitting the 240,000 rows between two tables took a combined 165 ms, faster than expected.
Step two: add CHECK constraints to the shadow tables:
ALTER TABLE sales_q1_new ADD CONSTRAINT ck_q1
CHECK (sale_date >= DATE '2026-01-01' AND sale_date < DATE '2026-04-01');
ALTER TABLE sales_q2_new ADD CONSTRAINT ck_q2
CHECK (sale_date >= DATE '2026-04-01' AND sale_date < DATE '2026-07-01');
ALTER TABLE
Time: 8.065 ms
ALTER TABLE
Time: 7.978 ms
By default, ATTACH performs a full-table scan to validate the partition constraint. If a suitable validated CHECK constraint already exists, it skips the scan. At larger data volumes, that can be the difference between minutes and seconds.
Perform the actual structural switch in a single transaction:
BEGIN;
SET LOCAL lock_timeout = '3s';
ALTER TABLE sales DETACH PARTITION sales_2026h1;
ALTER TABLE sales ATTACH PARTITION sales_q1_new
FOR VALUES FROM (DATE '2026-01-01') TO (DATE '2026-04-01');
ALTER TABLE sales ATTACH PARTITION sales_q2_new
FOR VALUES FROM (DATE '2026-04-01') TO (DATE '2026-07-01');
COMMIT;
BEGIN
Time: 0.058 ms
SET
Time: 0.058 ms
ALTER TABLE
Time: 0.220 ms
ALTER TABLE
Time: 6.705 ms
ALTER TABLE
Time: 6.626 ms
COMMIT
Time: 0.710 ms
Between DETACH and ATTACH, these 240,000 rows cannot be queried through the parent table. If the operations span separate transactions, the application sees a window in which those rows appear to be missing. In one transaction, external readers see either the complete old data or the complete data under the new structure, with no intermediate state.
The entire transaction took less than 15 ms. The three ALTER statements held the locks for a combined 13.5 ms. Keep lock_timeout: when a long-running transaction holds a lock, it is better for this attempt to fail and be retried than to make application writes queue up.
Reconcile the counts before dropping the old table:
SELECT (SELECT count(*) FROM sales_q1_new) AS q1_rows,
(SELECT count(*) FROM sales_q2_new) AS q2_rows;
SELECT c.relname AS partition, count(*) AS rows
FROM sales s JOIN pg_class c ON c.oid = s.tableoid
GROUP BY c.relname ORDER BY c.relname;
SELECT count(*) AS after_split FROM sales
WHERE sale_date >= DATE '2026-01-01' AND sale_date < DATE '2026-07-01';
DROP TABLE sales_2026h1;
q1_rows | q2_rows
---------+---------
119340 | 120662
(1 row)
Time: 8.937 ms
partition | rows
--------------+--------
sales_q1_new | 119340
sales_q2_new | 120662
(2 rows)
Time: 27.945 ms
after_split
-------------
240002
(1 row)
Time: 17.324 ms
DROP TABLE
Time: 3.892 ms
240002 before, 240002 afterward: no rows added or lost. Only then is it safe to drop the old table. Until validation finishes, the old partition is the only fallback.
Default partitions complicate archiving
Monthly archiving commonly uses DETACH CONCURRENTLY, which avoids blocking reads and writes and is available in 5.6. It has one strict condition: it cannot be used when the table has a default partition.
CREATE TABLE log_t (id int, d date) PARTITION BY RANGE (d);
CREATE TABLE log_t_2026 PARTITION OF log_t FOR VALUES FROM ('2026-01-01') TO ('2027-01-01');
CREATE TABLE log_t_def PARTITION OF log_t DEFAULT;
ALTER TABLE log_t DETACH PARTITION log_t_2026 CONCURRENTLY;
CREATE TABLE
Time: 1.322 ms
CREATE TABLE
Time: 1.301 ms
CREATE TABLE
Time: 1.283 ms
ERROR: cannot detach partitions concurrently when a default partition exists
Time: 0.114 ms
The error is explicit, with no workaround in that command. When the default partition is empty, ordinary DETACH is still quick:
ALTER TABLE log_t DETACH PARTITION log_t_2026;
ALTER TABLE log_t ATTACH PARTITION log_t_2026 FOR VALUES FROM ('2026-01-01') TO ('2027-01-01');
ALTER TABLE
Time: 0.585 ms
ALTER TABLE
Time: 0.674 ms
Archiving scripts should therefore check pg_partition_tree first. Deal with any default partition before detaching. For a regular partitioned table without a default partition, use concurrent detachment directly.
Is planning still fast with a thousand partitions?
Planning time was my main concern as the partition count increased. PG 18 specifically improved planning efficiency when accessing many partitions, and 5.6 inherits that improvement. After creating 1,000 monthly partitions, first count the nodes:
SELECT count(*) AS m_nodes FROM pg_partition_tree('m');
m_nodes
---------
1001
(1 row)
Time: 9.768 ms
All 1,001 nodes are present: 1,000 child partitions plus the parent. Compare this with a table containing 100 partitions, created by a DO block in 63.873 ms. Query one partition in each table:
EXPLAIN (ANALYZE, TIMING OFF) SELECT count(*) FROM m100 WHERE c = DATE '2003-07-15';
QUERY PLAN
--------------------------------------------------------------------------------------------------
Aggregate (cost=24.14..24.15 rows=1 width=8) (actual rows=1.00 loops=1)
-> Seq Scan on m100_200307 m100 (cost=0.00..24.12 rows=6 width=0) (actual rows=0.00 loops=1)
Filter: (c = '2003-07-15'::date)
Planning:
Buffers: shared hit=580
Planning Time: 0.834 ms
Execution Time: 0.022 ms
(7 rows)
Time: 1.609 ms
EXPLAIN (ANALYZE, TIMING OFF) SELECT count(*) FROM m WHERE c = DATE '2041-07-15';
QUERY PLAN
--------------------------------------------------------------------------------------------
Aggregate (cost=24.14..24.15 rows=1 width=8) (actual rows=1.00 loops=1)
-> Seq Scan on m_204107 m (cost=0.00..24.12 rows=6 width=0) (actual rows=0.00 loops=1)
Filter: (c = '2041-07-15'::date)
Planning:
Buffers: shared hit=3025
Planning Time: 4.348 ms
Execution Time: 0.022 ms
(7 rows)
Time: 4.572 ms
| Partition count | Planning Time | Planning Buffers |
|---|---|---|
| 100 | 0.834 ms | 580 |
| 1000 | 4.348 ms | 3025 |
A tenfold increase in partition count produced roughly a fivefold increase in planning time: sublinear growth. Pruning was clean as well. Each plan contained only one child table node, and execution time was 0.022 ms in both cases, with no degradation from the additional partitions.
Two smaller improvements are useful: \dP+ now displays the access method of partitioned tables, while VACUUM and ANALYZE accept ONLY, allowing maintenance of just the parent rather than hundreds of child partitions.
Common pitfalls
Create the CHECK constraints before ATTACH. Each shadow table took about 8 ms to constrain in this test, avoiding a full-table scan during attachment. With tens of gigabytes, this step can mean the difference between minutes and milliseconds. Build the indexes on the shadow tables too, so they can be attached directly instead of being rebuilt with another scan.
Keep DETACH and ATTACH in the same transaction, and set lock_timeout. Even a window lasting only a few milliseconds can look like missing data to the application.
Avoid a default partition when possible. It slows ATTACH and prevents DETACH CONCURRENTLY altogether. If you need one, check pg_partition_tree in the archiving script first.
A few hundred partitions should not be a major problem; the growth in this test was sublinear. But do not let the count grow indefinitely. With several thousand partitions, both planning and routine maintenance start to become burdensome.
Closing thoughts
Partitioning in 5.6 was easier to use than I expected. No changes were needed at the type level, there was a clear process for restructuring partitions, and planning overhead remained acceptable with a thousand partitions. The work lies in the operational details. Get those steps right once, then repeat the same process each month with little extra thought.
Previous post
Testing PostgreSQL 18 Index and Query Features on IvorySQL 5.6
Nov 9, 2026
Next post
PG 19 Plan Advice: “Matched” Does Not Mean the Plan Stayed the Same
Nov 30, 2026
Related Posts
Try IvorySQL
Get started with IvorySQL today. Read the docs or try our online demo.


