From d69234146ebab0a8c8f9a28fddd74161e5552a37 Mon Sep 17 00:00:00 2001 From: Mike Reeves Date: Mon, 10 Aug 2026 15:44:45 -0400 Subject: [PATCH] Let partman premake forward across the gap a stall leaves Retention drops every child once they all age out, partman refuses to drop the last one, and with infinite_time_partitions off it will not premake forward from a child that far in the past. The set is left with one stale partition and no current one, so metrics land right back in the default. Set infinite_time_partitions on telegraf parents, in both the repair script and the retention subcommand, and stop blaming the launcher when pg_cron is not loaded at all. --- salt/postgres/tools/sbin/so-telegraf-postgres | 5 +++- salt/postgres/tools/sbin/so-telegraf-repair | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/salt/postgres/tools/sbin/so-telegraf-postgres b/salt/postgres/tools/sbin/so-telegraf-postgres index 8a85f9443..df7d16e65 100644 --- a/salt/postgres/tools/sbin/so-telegraf-postgres +++ b/salt/postgres/tools/sbin/so-telegraf-postgres @@ -234,10 +234,13 @@ EOSQL SELECT CASE WHEN EXISTS (SELECT 1 FROM pg_catalog.pg_extension WHERE extname = 'pg_partman') THEN 'true' ELSE 'false' END AS has_partman \gset \if :has_partman +-- infinite_time_partitions so a gap in metrics does not stop partman from +-- premaking forward, which is what leaves everything in the default. UPDATE partman.part_config SET retention = :'retention_days' || ' days', retention_keep_table = false, - premake = 7 + premake = 7, + infinite_time_partitions = true WHERE parent_table LIKE 'telegraf.%'; \endif EOSQL diff --git a/salt/postgres/tools/sbin/so-telegraf-repair b/salt/postgres/tools/sbin/so-telegraf-repair index 2076ea1a4..ddfa5f7d7 100644 --- a/salt/postgres/tools/sbin/so-telegraf-repair +++ b/salt/postgres/tools/sbin/so-telegraf-repair @@ -102,9 +102,12 @@ parents=$(psql_tg -tAc \ stranded=$(psql_tg -tAc "SELECT coalesce(sum(default_rows), 0) FROM ( $REPORT ) t") behind=$(psql_tg -tAc \ "SELECT count(*) FROM ( $REPORT ) t WHERE coalesce(days_ahead, -1) < 1") -low_premake=$(psql_tg -tAc \ +# premake < 7, or infinite_time_partitions off: without the latter partman +# refuses to premake forward across the gap the stall left behind. +misconfigured=$(psql_tg -tAc \ "SELECT count(*) FROM partman.part_config - WHERE parent_table LIKE 'telegraf.%' AND premake < $PREMAKE") + WHERE parent_table LIKE 'telegraf.%' + AND (premake < $PREMAKE OR NOT infinite_time_partitions)") # Both columns are matched because which one carries the launcher's name varies # with the pg_cron version. @@ -124,14 +127,15 @@ if [[ -n "$cron_db" ]]; then [[ -n "$last_run" ]] || last_run=never fi -# A grid that has never written a metric has nothing to recover. +# A grid that has never written a metric has nothing to recover, and an empty +# cron_db means pg_cron is not loaded at all, which no restart fixes. restart_needed=false -[[ "$launcher" -eq 0 && "$parents" -gt 0 ]] && restart_needed=true +[[ "$launcher" -eq 0 && "$parents" -gt 0 && -n "$cron_db" ]] && restart_needed=true repair_needed=false [[ "$stranded" -gt 0 ]] && repair_needed=true [[ "$behind" -gt 0 ]] && repair_needed=true -[[ "$low_premake" -gt 0 ]] && repair_needed=true +[[ "$misconfigured" -gt 0 ]] && repair_needed=true $restart_needed && repair_needed=true echo "Telegraf partition status:" @@ -151,7 +155,7 @@ if $CHECK_ONLY; then echo "Repair is needed:" [[ "$stranded" -gt 0 ]] && echo " * $stranded row(s) stranded in default partitions" [[ "$behind" -gt 0 ]] && echo " * $behind parent(s) with no partition for the current window" - [[ "$low_premake" -gt 0 ]] && echo " * $low_premake parent(s) premaking fewer than $PREMAKE days ahead" + [[ "$misconfigured" -gt 0 ]] && echo " * $misconfigured parent(s) with stale partman settings" $restart_needed && echo " * pg_cron's launcher is dead; maintenance is not running at all" echo echo "Re-run without --check to repair." @@ -167,11 +171,13 @@ if [[ "$stranded" -gt 0 ]] && ! $ASSUME_YES; then [[ "$answer" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 0; } fi -if [[ "$low_premake" -gt 0 ]]; then - echo "Raising premake to $PREMAKE on $low_premake parent(s)." - # GREATEST so an operator who raised it further keeps their value. +if [[ "$misconfigured" -gt 0 ]]; then + echo "Reconciling partman settings on $misconfigured parent(s)." + # GREATEST so an operator who raised premake further keeps their value. psql_tg -v ON_ERROR_STOP=1 -c \ - "UPDATE partman.part_config SET premake = GREATEST(premake, $PREMAKE) + "UPDATE partman.part_config + SET premake = GREATEST(premake, $PREMAKE), + infinite_time_partitions = true WHERE parent_table LIKE 'telegraf.%'" fi