Skip to content

kingres_timepart

Time-range partition creation, retention policies and maintenance history.

kingres · Time-range partition creation, retention policies and maintenance history.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102356kingres_timepartkingres0.4TIMEAGPL-3.0-onlySQL

PostgreSQL · 18, 19

Usage

Sources:

kingres_timepart 0.4 manages creation, columnar conversion and retention of time-range partitions through SQL and PL/pgSQL. It supports ordinary tables and user-partitioned distributed tables with kingres_shard 0.10. The source targets PostgreSQL 18.7 and 19.0. It has no own shared library, preload setting or background scheduler.

Define and Inspect a Policy

Installation needs a superuser because it creates event triggers. The example is an administrative workflow: retention can drop old partitions. Inspect the plan first, and call the procedure outside a transaction block.

CREATE EXTENSION kingres_timepart;
CREATE TABLE public.events (ts timestamptz, payload text) PARTITION BY RANGE (ts);
SELECT kingres.timepart_set_policy(
    'public.events', '1 day', create_ahead => '7 days', retention => '30 days'
);
SELECT * FROM kingres.timepart_plan('public.events');
CALL kingres.timepart_run('public.events');

Tables require a single plain date, timestamp or timestamptz RANGE key and no DEFAULT partition. Time grids default to UTC and distinguish calendar days from fixed hours. Misaligned partitions are reported and not automatically converted or retired.

Maintenance and Privileges

Owners with explicit grants can configure policies and use kingres.create_time_partitions, kingres.drop_old_time_partitions, kingres.timepart_plan and kingres.timepart_check. kingres.timepart_policies and run-history views filter state by owner. There is no work until an external caller or the control plane runs the policy.

The run driver is restricted by default. A superuser can grant the reviewed owner-driver path with kingres.timepart_grant_driver; this permits an owner to run its own tables without granting unrestricted maintenance. Operations commit between actions, so a failure does not roll back earlier work. Superuser maintenance of another owner’s table has additional owner-code checks; review the documented trust boundary before granting or acknowledging it.

Conversion, Distribution and Upgrade

kingres.convert_partition replaces one leaf with a columnar or heap copy; kingres.convert_old_partitions converts qualifying leaves one transaction at a time. Columnar conversion requires kingres_columnar 0.2 and its library preloaded on all participating nodes. Review index, dependency and storage restrictions before conversion.

A snapshot older than the conversion can see the replaced partition as empty if it first reads the table after the swap; this affects REPEATABLE READ, SERIALIZABLE and exported snapshots. Plan conversions around long-lived readers.

Distributed policies run on the map-group primary and require kingres_shard 0.10. Their creation/retirement uses distributed DDL; do not assume a partially upgraded cluster is detected automatically. Update columnar storage first, then apply the supplied 0.1-to-0.2-to-0.3-to-0.4 SQL chain. Retention can drop or detach data, and conversion is no longer a reserved, unimplemented policy field.

0.4: Respect Feature Locks

Version 0.4 checks kingres.feature_set when setting policies, creating or dropping time partitions, adopting partitions and beginning policy runs. If another registered extension locks timepart, the operation fails with KE007 and explains the conflict. Existing data remains readable and policies can still be removed. Without kingres_shard, this feature lock does not exist and previous behavior continues.

After installing matching files, use the supplied 0.3-to-0.4 script through ALTER EXTENSION kingres_timepart UPDATE TO '0.4'. This is an independent SQL version update, not the KingresDB distribution version.

Table reader