Query icon
OutputValues icon
Log icon
If icon
SlackIncomingWebhook icon
Pause icon
Loop icon
Fail icon
Schedule icon

Vertica Out of Date Projection Refresh Guard

Detect Vertica projections that are not up to date, refresh them behind an approval gate then re-read the catalog to prove the refresh landed.

Categories
DataInfrastructure

Create or alter a projection on a Vertica table that already holds rows and the new projection arrives empty. The catalog marks it is_up_to_date = false and Vertica will not let the optimizer use it until someone refreshes it from the anchor table. Nothing breaks. Queries keep returning correct answers off the older projection, just slower. The physical design you just deployed buys nothing. The only signal is a WARNING 4468 at create time, which is long gone by the time anyone wonders why the new sort order made no difference.

This guard reads v_catalog.projections, keeps every row where is_up_to_date is false, joins v_catalog.tables for the anchor schema and v_monitor.projection_storage for the number of rows the refresh has to rebuild, then alerts Slack. When you let it, it asks a human first, then runs SELECT REFRESH() once per anchor table rather than once per projection, because REFRESH takes a table and refreshes every stale projection on it. It then reads is_up_to_date again for exactly the projections it targeted and fails the run if any of them is still false.

This blueprint was created by zkasuran.

Findings

Finding Meaning
Projection not up to date A projection exists in the catalog but holds no data for part or all of its anchor table. The optimizer skips it, so the sort order, encoding or segmentation it was created for is not being used. Until it is refreshed the work spent designing and deploying it is wasted.

Safety

REFRESH rebuilds a projection by reading the whole anchor table, so the cost scales with the table. That is why the report carries the anchor row count and why the refresh sits behind a Pause. The guard stays read-only until auto_remediate is true and dry_run is false. Even then it waits for a human to resume the approval gate. An unanswered pause reads as a refusal. The refresh loop runs one anchor table at a time so two rebuilds do not compete for the same resource pool. The re-verify is scoped to the projections the run reported, so a projection created stale somewhere else while the run was in flight does not fail it.

The re-verify is not a formality. REFRESH is a meta-function that reports its outcome in the result row instead of raising, so a refresh the database refused still looks like a successful query to the driver. Reading is_up_to_date again is the only way to tell the two apart.

How it works

  1. audit (io.kestra.plugin.jdbc.vertica.Query, read-only) reads v_catalog.projections for is_up_to_date = false, joins v_catalog.tables on anchor_table_id for the anchor schema and v_monitor.projection_storage for the anchor row count, filters by anchor_schema_filter and builds a SELECT REFRESH(...) statement per anchor table.
  2. targets groups the findings by anchor table, keeps the quoted projection keys for the re-verify and totals the rows the refresh has to rebuild. summary logs the stale projections with their anchor row counts and how each one was created.
  3. route (io.kestra.plugin.core.flow.If) branches on whether anything was found.
    • clean: logs it.
    • found: alert posts to Slack. remediate_gate runs only when auto_remediate is true and dry_run is false.
      • approval_gate (io.kestra.plugin.core.flow.Pause) holds the run until a human resumes it with approved: true. apply reads that answer and treats anything else as a refusal.
      • remediate (io.kestra.plugin.core.flow.Loop, concurrencyLimit: 1) runs one SELECT REFRESH() per anchor table.
      • reverify and verify_result read is_up_to_date again for the targeted projections and fail the run through io.kestra.plugin.core.execution.Fail if any is still false.
  4. errors posts a Slack alert when any task fails.

What you get

  • The projections the optimizer is ignoring, with the anchor table, the anchor row count and whether the projection came from CREATE PROJECTION or Database Designer.
  • The cost of the fix before you approve it, as the row count each refresh has to rebuild.
  • A read-only default plus a human approval gate. Nothing is refreshed on two input flags alone.
  • One REFRESH per anchor table instead of one per projection, so a table with three stale projections is rebuilt once.
  • A re-verify that reads the catalog back and fails the run if a projection is still stale.

Who it's for

  • Teams that deploy physical design changes (new sort orders, new encodings, Database Designer output) onto live tables and need to know the new projections are actually in use.
  • DBAs who have hit the case where a query plan ignores a projection that exists and looks healthy in every other respect.
  • Anyone running the Vertica plugin who wants an example that reads the system catalog, decides from it and verifies its own write.

Why orchestrate this with Kestra

Vertica never refreshes a projection on its own. It also never fails a query because of a stale one, so there is no alert to react to and nothing in a dashboard goes red. The check is a catalog read nobody remembers to run. The fix is expensive enough that it should not run unattended. Kestra puts the read on a schedule, reports the cost before the write, holds the write behind an approval, serialises the refreshes then proves the result by reading the catalog again, with the whole history kept per run.

Tested end to end

On Kestra 2.0.5 OSS against Vertica Community Edition 9.2 (database docker, schema analytics), with the shared HTTP sink standing in for Slack. analytics.orders was loaded with 50000 rows by COPY, then CREATE PROJECTION analytics.orders_by_cust on the populated table landed is_up_to_date = false. A second table analytics.customers carried a projection created while it was empty and then populated, which stays up to date and was never touched, so the detector had something to be wrong about. is_up_to_date was read directly in vsql before and after every run.

Run Inputs Result
1 clean database, every projection refreshed SUCCESS (5eI5EjHfmOqv17PBUfso1J). audit returned 0 rows. Clean path logged
2 degraded, dry_run true SUCCESS (2IhNSswkaDG3Ll4XRs9qmY). 1 projection reported (analytics.orders_by_cust, 50000 anchor rows, created by CREATE PROJECTION). Slack alert sent. is_up_to_date stayed f
3 auto_remediate true, dry_run true SUCCESS (7DXSdw7jBe3si9XCeB6WCp). Same report. dry_run held the gate closed, so the run never paused and is_up_to_date stayed f
4 auto_remediate true, dry_run false, resumed with approved false SUCCESS (7C1GT7wDyTmZ1VzPonknqm). Paused at approval_gate, the refusal was recorded by declined and is_up_to_date stayed f
5 auto_remediate true, dry_run false, resumed with approved true SUCCESS (7cacKOIoBn80h8iYjIYSXO). One REFRESH on analytics.orders. The re-verify came back empty. is_up_to_date went f to t and the projection went from 0 to 50000 rows, both read back in vsql
6 degraded again, dry_run true, after run 5 SUCCESS (2VqlYRb9Mu1qUJi1Lt9vTC). 0 projections reported where run 2 reported 1
7 stale again, connected as a user holding only SELECT on the anchor table FAILED (5ht3AtBFNGM4K9vckAUCXV). REFRESH returned [failed: insufficient permissions on table "analytics.orders"] as a result row, so the task itself succeeded. The re-verify still found the projection stale, verify_result failed the run and the errors block alerted Slack
8 unreachable database FAILED (6vNAIhaCwNTs7n1Aazzq10). audit could not connect, so the errors block posted the failure alert
9 degraded, dry_run true, final file SUCCESS (5ez5zAuzE0AAerfAcVzsZd). Validate clean, 1 projection reported at 50000 anchor rows
10 same as run 7, final file FAILED (PHAJc1peGjFIr7sBlWm4E). The refresh was refused again, the re-verify caught it and the run failed

Run 2 against run 6 is the proof the detector can fail: the same query reported one stale projection at 50000 anchor rows and then zero after the refresh. analytics.customers_by_region held 500 rows, stayed up to date throughout and was never reported, so the detector is precise and not just counting projections. Run 7 is the proof the verify gate earns its place: the refresh task reported success while the catalog still said the projection was stale. Only the second read caught it.

Prerequisites

  • A reachable Vertica cluster and its JDBC URL in jdbc_url.
  • For the audit, a user that can read v_catalog.projections, v_catalog.tables and v_monitor.projection_storage. For the refresh, a user that owns the anchor tables or is a superuser.
  • Local testing: docker run -d --name vertica jbfavre/vertica:latest brings up a single node with database docker and user dbadmin.

Secrets

  • VERTICA_PASSWORD: password for the Vertica user. The password input defaults to it.
  • SLACK_WEBHOOK_URL: used by alert and the errors block.
  • In Kestra OSS, provide each one as a base64-encoded environment variable prefixed SECRET_.

Inputs

Input Default Purpose
jdbc_url jdbc:vertica://vertica:5433/VMart Vertica cluster to check
username dbadmin Vertica user
password {{ secret('VERTICA_PASSWORD') }} Password for that user
anchor_schema_filter % LIKE pattern on the anchor table schema
auto_remediate false Allow the refresh to be proposed
dry_run true Must be false before the approval gate is reached

Quick start

  1. Add the VERTICA_PASSWORD and SLACK_WEBHOOK_URL secrets.
  2. Import the flow and set jdbc_url and username.
  3. Run it once with the defaults and read the stale projections and their anchor row counts.
  4. When the cost looks acceptable, run with auto_remediate: true and dry_run: false, then resume the paused execution with approved: true.
  5. Enable the daily trigger, which always runs in safe mode.

How to extend

  • Narrow anchor_schema_filter to one schema per run so a nightly sweep never queues a refresh of your largest fact table.
  • Add a row ceiling to the audit so only small tables are refreshed automatically and large ones are reported for a maintenance window.
  • Swap REFRESH for START_REFRESH, which returns straight away and refreshes in the background, when the run should not hold a slot open.
  • Report has_statistics alongside is_up_to_date and run ANALYZE_STATISTICS on the refreshed tables in the same pass.
  • Replace the Slack alert with PagerDuty, Microsoft Teams or email.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.