Maintenance with the AWS Glue Data Catalog table optimizer
For self-managed Iceberg tables that are registered in the AWS Glue Data Catalog, you can offload compaction, snapshot expiration, and unreferenced-file deletion to the table optimizer. Once enabled, the AWS Glue Data Catalog runs the corresponding maintenance jobs on your behalf without any code or scheduler on your side. The optimizer can be configured per table or catalog-wide (so that every new or updated Iceberg table inherits the configuration). See Optimizing Iceberg tables and Catalog-level table optimizers in the AWS Glue documentation for setup steps and IAM requirements.
This section documents the customizable parameters, their defaults, and where each optimizer reads its inputs from.
Compaction optimizer
The compaction optimizer merges small data files into larger ones and can apply delete files on merge-on-read tables. It runs continuously: the Data Catalog starts a compaction job for a table or partition when it holds more than minInputFiles (default 100) files that are each smaller than 75% of write.target-file-size-bytes.
Parameter | Purpose | Default |
|---|---|---|
| Rewrite strategy. For |
|
| Minimum number of small files in a partition before the optimizer triggers a compaction for that partition |
|
| On merge-on-read tables, compact a data file if it has at least this many associated delete files |
|
Target file size | Target size for compacted output files. The optimizer reads this from the table property | 512 MB ( |
Notes:
To use the
sortorz-orderstrategy, set the table's sort order first (for example,ALTER TABLE mydb.orders WRITE ORDERED BY customer_id). The optimizer will use that sort order for the rewrite; without a sort order defined on the table, bothsortandz-orderfall back to the equivalent ofbinpack.To change the target file size, update the table property:
ALTER TABLE mydb.orders SET TBLPROPERTIES ('write.target-file-size-bytes' = '536870912').
Snapshot retention optimizer
The snapshot retention optimizer runs expire_snapshots on a schedule to trim the table history.
Parameter | Purpose | Default |
|---|---|---|
| Only expire snapshots older than this many days | If not specified, the optimizer uses (1) the table property |
| Minimum number of most-recent snapshots to keep, even if they exceed the retention period | If not specified, the optimizer uses (1) the table property |
| How often the retention job runs, between 3 and 168 hours | 24 hours |
| Delete the data and metadata files of expired snapshots. If false, snapshots leave the metadata but their files stay on Amazon S3 as unreferenced files. | true |
Notes:
You can control the retention policy centrally by setting the table properties
history.expire.max-snapshot-age-msandhistory.expire.min-snapshots-to-keep(self-managed tables only; do not set these on tables in Amazon S3 Tables). Any manual Sparkexpire_snapshotsinvocation will pick up the same values, so the policy stays consistent whether the Data Catalog optimizer or a Spark job is doing the work.Keep at least enough snapshots (or a long enough retention period) to meet your recovery point objective for time travel and rollback.
Unreferenced files deletion optimizer
The unreferenced-files deletion optimizer scans the table's storage location and deletes files that are no longer referenced by any snapshot metadata.
Parameter | Purpose | Default |
|---|---|---|
| Only consider files older than this many days as candidates for deletion (protects concurrent writers) | 3 days |
| How often the unreferenced-files deletion job runs, between 3 and 168 hours | 24 hours |
Notes:
The retention period is a safety buffer against files that are currently being written but not yet committed. Do not lower it below the maximum realistic duration of a write job against the table.
On tables with concurrent writers or with data written outside Iceberg (for example, by a Amazon Data Firehose that lands files then commits), keep the default 3-day retention or increase it further.
Turning it off (fall back to self-managed maintenance)
You can disable any of the three optimizers per table at any time (through the AWS Glue console, AWS CLI, or UpdateTableOptimizer API). If you do, you can fall back to running the equivalent Iceberg system procedures yourself — see Self-managed maintenance. It's also fine to use the optimizer for some activities (for example, compaction and snapshot retention) and run others manually (for example, remove_orphan_files on demand from Spark).
Observability
AWS Glue publishes Amazon CloudWatch metrics after each successful optimizer run: bytes and files compacted, DPUs allocated, and job duration for compaction; data files, manifest files, and manifest lists deleted for snapshot retention; files deleted for unreferenced file deletion. To see failed runs and their error messages, use ListTableOptimizerRuns or the optimizer history in the AWS Glue console. For the metric list, see Viewing Amazon CloudWatch metrics.