All Products
Search
Document Center

Hologres:Compact data files

Last Updated:Aug 12, 2026

After importing large volumes of data or running many DELETE or UPDATE operations, data file fragmentation can degrade read and write performance. Compaction merges small data files into larger ones, restoring storage efficiency and improving query speed.

How it works

Hologres uses a data structure similar to an LSM-Tree (log-structured merge-tree) for data writes. All writes are append-only, converting random writes into sequential writes to maximize write throughput. Over time, this produces many small files that must be merged through compaction.

Hologres supports two compaction types:

  • Auto compaction: Hierarchical compaction with up to five levels. When a level accumulates more than five files, compaction triggers automatically and moves the result to the next level. For example, five files at Level 0 merge into a single file (up to 64 MB by default) that moves to Level 1. Auto Compaction only merges files within the same level—never across levels.

  • Full compaction: Merges all files across all levels into new files (64 MB each by default) placed at the final level. Full compaction must be triggered manually.

image.png

When to run full compaction

Auto compaction handles routine file merging continuously in the background. Run full compaction only when file fragmentation has accumulated beyond what auto compaction can address incrementally—specifically, after either of these situations:

  • Importing large volumes of offline data

  • Running many DELETE or UPDATE operations

Note

Full compaction is a resource-intensive administrative operation. It consumes significant I/O and CPU resources. Execution typically takes more than 10 minutes. Run it during low-write periods to minimize impact on your workload.

Run full compaction

Prerequisites and limitations

  • Full compaction requires Hologres V2.1 or later. To upgrade, see Upgrade an instance or get online support to request an upgrade.

  • Only column-oriented tables and hybrid row-column tables support full compaction.

  • For hybrid row-column tables, full compaction applies only to the column store portion.

Syntax

SELECT hologres.hg_full_compact_table(
  '<schema_name.table_name>'
  [,'max_file_size_mb=<value>']
);

Parameters

Parameter

Description

Required

Default

schema_name.table_name

Name of the table to compact

Yes

max_file_size_mb

Maximum size in MB for each output file. Must be a positive integer. Setting this value too low creates too many small files, which slows down queries. Do not change this value unless necessary.

No

64

Examples

Run full compaction on public.lineitem:

SELECT hologres.hg_full_compact_table('public.lineitem');

Run full compaction on public.lineitem with a maximum output file size of 256 MB:

SELECT hologres.hg_full_compact_table(
  'public.lineitem',
  'max_file_size_mb=256'
);

Tune auto compaction for a single table

Full compaction is a manual, one-off operation. To change how auto compaction behaves on a single table, set table properties on that table. These properties control compaction concurrency, file selection, and trigger frequency. Use them to pause compaction during a bulk load, clear out accumulated small files, or relieve resource contention caused by background compaction.

Prerequisites and limitations

  • These table properties require Hologres V4.0 or later. On earlier versions, setting them has no effect. Upgrade the instance first.

  • These properties apply only to column-oriented tables and hybrid row-column tables. For a hybrid row-column table, they affect only the column store portion. Setting them on a row-oriented table has no effect.

  • Auto compaction needs no manual intervention in most cases. Apart from online_config_compaction_semaphore, the advanced properties interact with concurrency settings in ways that are hard to predict. Change them only to address a specific problem, preferably with guidance from technical support, and restore the defaults afterward.

Set, query, and reset table properties

Set table-level compaction properties with SET_TABLE_PROPERTY. Every property name carries the online_config_ prefix, and every value is passed as a string. A new value applies to compaction tasks scheduled after the change; tasks already running are unaffected. You do not need to restart the instance or rebuild the table.

-- Syntax
CALL SET_TABLE_PROPERTY('<schema_name>.<table_name>', 'online_config_<property_name>', '<value>');

-- Pause compaction scheduling on public.orders
CALL SET_TABLE_PROPERTY('public.orders', 'online_config_compaction_semaphore', '0');

Reset a property

Set a property to reset to remove the table-level override and return the table to the instance default.

CALL SET_TABLE_PROPERTY('public.orders', 'online_config_compaction_semaphore', 'reset');
Important

If the table already carries an override that your workload depends on—for example, a value of 4 that was set deliberately—write that value back instead of using reset. Record the current state before you change anything. See Query the current settings.

Query the current settings

SELECT property_key, property_value
FROM hologres.hg_table_properties
WHERE table_namespace = '<schema_name>'
  AND table_name = '<table_name>'
  AND property_key LIKE 'online_config_%';

An empty result means the table has no table-level override and follows the instance default.

Control compaction concurrency

online_config_compaction_semaphore is the property to reach for first. It caps concurrent compaction tasks per tablet, not per table—a tablet is the unit that compaction is scheduled against. A table has one or more tablets on each shard; in a hybrid row-column table, the row store and column store portions are separate tablets. The theoretical ceiling for the whole table is therefore roughly tablet_count × property_value, though the worker-level concurrency limit and available resources usually cap it lower.

Value

Behavior

When to use

0

Stops scheduling new compaction tasks for the table.

A temporary window before a bulk load. Always restore the value afterward.

1

Keeps the minimum merging capability.

Compaction is visibly affecting online queries and you need to shed load.

2

Default.

Almost all workloads.

3 to 8

Increases merge throughput.

Files keep accumulating and the instance has spare resources. Raise the value by 1 at a time.

What setting the value to 0 actually does

  • New compaction tasks for the table are no longer scheduled.

  • Tasks already running are not cancelled. They finish normally.

  • Tasks that were already selected for this table and are waiting to run still hold worker-level concurrency slots. Setting many tables to 0 at once therefore starves compaction on other tables.

  • After you raise the value above 0, queued tasks resume, but a backlog that was never scheduled is not guaranteed to be picked up on its own—especially if the table receives no new writes. Run VACUUM once to force the backlog through. For what VACUUM does and does not do, see Examples.

To restore concurrency and merge the backlog:

CALL SET_TABLE_PROPERTY('public.orders', 'online_config_compaction_semaphore', '2');
VACUUM public.orders;

Logical partitioned tables

For a logical partitioned table, Hologres raises concurrency in proportion to the number of active partitions. The ceiling for a single scheduling unit is min(online_config_partition_table_compaction_semaphore_max, active_partition_count × online_config_compaction_semaphore), capped at 8 by default. active_partition_count is measured at runtime and is not a property you can set.

Risks

  • Do not leave the value at 0 for long. File counts and deleted rows keep accumulating, query performance and storage usage both degrade, and the longer the backlog grows, the heavier the eventual merge.

  • Do not set 0 or raise the value across many tables at once. All tables share the worker-level concurrency budget: a mass pause lets queued tasks occupy that budget, and a mass increase causes global queuing and a resource spike.

  • Change one table and one property at a time, in the smallest useful increment, and observe a full business cycle before the next change.

Advanced properties

The following properties change how compaction selects files and how often it triggers. They interact with the concurrency settings, so change them only for a specific diagnosed problem—ideally with guidance from technical support—and restore the defaults afterward.

Property

Default

Description

online_config_partition_table_compaction_semaphore_max

8

Upper bound on compaction concurrency for a single scheduling unit of a logical partitioned table. Combined with online_config_compaction_semaphore in the formula given in Control compaction concurrency.

online_config_parts_to_merge

5

Maximum number of input files a single compaction task selects.

online_config_trigger_compaction_picker_threshold

5

Number of candidate files required to trigger a compaction task. The effective threshold is the smaller of this value and online_config_parts_to_merge.

online_config_orc_max_total_size_to_merge_mb

256

Total size in MB of the files a single compaction task selects for a column-oriented table, or for the column store portion of a hybrid row-column table. Indirectly determines the size of the merged output.

online_config_max_total_size_to_merge_mb

512

Total data volume in MB a single compaction task selects on non-columnar data paths.

online_config_deletion_compaction_ratio

30

Percentage of deleted rows in a file above which the file is compacted in place to reclaim space.

online_config_ignore_level_compaction

false

Ignores level boundaries during file selection, allowing cross-level merges. Use it to clear long-tail small files that sit a few per level and never reach the trigger threshold.

online_config_bottom_level_compaction

true

Whether files at the bottom level participate in compaction.

Note

Worker-level total compaction concurrency—the ceiling shared by all tables on a single worker node—is an instance-level setting, not a table property, and cannot be changed with SET_TABLE_PROPERTY. Contact technical support if you need it adjusted.

Examples

Note

Examples 2 and 3 change advanced properties. Run them with guidance from technical support, and restore the defaults once the issue is resolved.

Example 1: Pause compaction for a bulk load

-- 1. Record the current state. An empty result means no override is set.
SELECT property_key, property_value FROM hologres.hg_table_properties
WHERE table_namespace = 'public' AND table_name = 'orders'
  AND property_key = 'online_config_compaction_semaphore';

-- 2. Stop scheduling new compaction tasks.
CALL SET_TABLE_PROPERTY('public.orders', 'online_config_compaction_semaphore', '0');

-- 3. Run the bulk load. Watch CPU, I/O, and load throughput while it runs.

-- 4. Restore the property. Choose one of the following based on step 1.
-- 4a. Step 1 returned no rows:
CALL SET_TABLE_PROPERTY('public.orders', 'online_config_compaction_semaphore', 'reset');
-- 4b. Step 1 returned a value. Write that value back:
-- CALL SET_TABLE_PROPERTY('public.orders', 'online_config_compaction_semaphore', '<original_value>');

-- 5. Merge the backlog. Run this during a low-write period.
VACUUM public.orders;

Example 2: Clear long-tail small files

Use this when every level holds fewer files than the trigger threshold, yet the table has accumulated dozens of small files that never merge.

CALL SET_TABLE_PROPERTY('public.orders', 'online_config_ignore_level_compaction', 'true');
VACUUM public.orders;
-- Restore the default once the file count drops. Leaving it on inflates compaction
-- frequency and CPU and I/O usage on continuously written tables.
CALL SET_TABLE_PROPERTY('public.orders', 'online_config_ignore_level_compaction', 'reset');

Example 3: Produce larger merged files

Use this when a tablet holds a large volume of data spread across many files.

CALL SET_TABLE_PROPERTY('public.orders', 'online_config_orc_max_total_size_to_merge_mb', '512');
VACUUM public.orders;
-- Restore the default once the file count drops.
CALL SET_TABLE_PROPERTY('public.orders', 'online_config_orc_max_total_size_to_merge_mb', 'reset');
Note

In Hologres, VACUUM <table_name> flushes the table and waits for its compaction tasks to converge. It is a way to trigger auto compaction—useful after raising online_config_compaction_semaphore from 0, or after changing a selection property—but it is not equivalent to full compaction and does not force a cross-level merge of every file.

Verify that a change took effect

  1. Property names are not validated. Any name after the online_config_ prefix is accepted and the statement succeeds. A misspelled name matches no configuration, so the change silently does nothing. To protect against this:

    • Copy property names from the tables in this topic instead of typing them.

    • Confirm the write by querying hologres.hg_table_properties.

    • Confirm the behavior actually changed by watching file counts and file sizes. A statement that succeeds proves nothing on its own.

  2. Partitioned tables inherit properties only at creation. Running SET_TABLE_PROPERTY on a parent table does not affect existing child partitions. The property is written to the parent alone, and the parent holds no data, so compaction behavior on existing partitions is unchanged. Child partitions copy the parent's properties once, when they are created—including partitions created automatically by dynamic partitioning—and later changes to the parent are not propagated. To change compaction behavior on a partitioned table, run SET_TABLE_PROPERTY on each target child partition and verify each one. Set the property on the parent as well if you want future partitions to inherit it.

  3. Close the loop with observation. Query hologres.hg_table_file_status for the current file count and file sizes, hologres.hg_partition_file_status for a per-partition view of a logical partitioned table, and hologres.hg_table_info (produced once a day) to review trends. A successful adjustment shows a falling total file count and a rising average file size. Storage usage can rise briefly while merged-away files await cleanup; this is expected.

    SELECT * FROM hologres.hg_table_file_status('<schema_name>.<table_name>'::regclass);

Reference

Run compaction tasks using Serverless Computing