Documentation
¶
Overview ¶
Package pgpartition maintains daily PostgreSQL RANGE partitions and enforces retention policies (dropping expired scratch/dedupe partitions or concurrently detaching expired domain partitions), optionally propagating pgtx tenant RLS policies to newly created child partitions.
Index ¶
- func DailyPartitionName(table string, day time.Time) string
- func NewModule(opts Options) appkit.Module
- func ParsePartitionDate(relname string) (time.Time, bool)
- func RetentionCutoff(now time.Time, retentionDays int) (time.Time, bool)
- type MaintenancePlan
- type Options
- type Report
- type RetentionAction
- type TableReport
- type TableSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DailyPartitionName ¶
DailyPartitionName returns "<tableName>_pYYYYMMDD" for the given UTC day.
func NewModule ¶
NewModule registers an optional startup maintenance pass (when RunOnStart is true) and a periodic cluster-locked maintenance worker via appkit/job.Every.
func ParsePartitionDate ¶
ParsePartitionDate extracts the UTC date from a daily partition table name such as "events_p20261129" or "events_p_20261129".
func RetentionCutoff ¶
RetentionCutoff returns the exclusive UTC midnight cutoff date (todayUTC - retentionDays). Daily partitions strictly before this date are considered expired. Returns (zero, false) when retentionDays <= 0.
Types ¶
type MaintenancePlan ¶
type MaintenancePlan struct {
Schema string
Table string
CreateSQL []string
CreatedNames []string
ExpireSQL []string
}
MaintenancePlan holds the deterministic DDL statements planned for a table.
func PlanTable ¶
func PlanTable(spec TableSpec, now time.Time, daysAhead int, existing []string) (MaintenancePlan, error)
PlanTable generates deterministic SQL DDL statements to: 1. Create missing daily RANGE partitions from today-1 through today+daysAhead. 2. Drop or concurrently detach expired daily partitions strictly older than RetentionDays.
type Options ¶
type Options struct {
Log *slog.Logger
Pool *pgxpool.Pool
LockPool *pgxpool.Pool
DaysAhead int
Interval time.Duration
LockName string
RunOnStart bool
Tables []TableSpec
Now func() time.Time
}
Options configures partition maintenance execution and its background appkit.Module.
type Report ¶
type Report struct {
Tables []TableReport
}
Report summarizes one EnsurePartitions run across all configured tables.
func EnsurePartitions ¶
EnsurePartitions inspects each configured table in Postgres, skips tables that do not exist or are not partitioned (relkind != 'p'), creates future daily partitions (propagating pgtx tenant RLS policies when enabled and parent has RLS enabled), and drops/detaches expired daily partitions.
type RetentionAction ¶
type RetentionAction string
RetentionAction specifies what happens to expired daily partitions on a table.
const ( ActionKeep RetentionAction = "keep" ActionDetach RetentionAction = "detach" ActionDrop RetentionAction = "drop" )
type TableReport ¶
TableReport summarizes maintenance results for one configured table.