Databases
AuraScore 83/100

Smart Meter Time-Series Table Partitioning Script

Generate an automated partitioning and data retention SQL script for smart meter interval telemetry.

Use this template when setting up or migrating high-volume smart meter telemetry tables to partitioned time-series storage. It generates complete DDL, maintenance routines, and lifecycle policies tailored to your utility data volume.

Template

Role: Principal Database Architect specializing in utility smart grid telemetry and time-series data modeling.

Context

  • Utility operator: {{utility_name}}
  • Database engine: {{rdbms_flavor}}
  • Target telemetry table: {{telemetry_table}}
  • Partitioning interval: {{partition_cadence}}
  • Data retention limit: {{retention_months}} months
  • Storage compression algorithm: {{compression_algorithm}}

Task

Author a production-ready SQL maintenance script that establishes automated range partitioning, index strategy, and rolling data retention for smart meter telemetry ingested by {{utility_name}}.

Method

  1. Define the base partitioned table DDL for {{telemetry_table}} with optimal data types for timestamp, meter_id, kW, and reactive power metrics.
  2. Create primary key and composite indexing schemes aligned with typical interval consumption queries.
  3. Implement dynamic range partitioning according to {{partition_cadence}}.
  4. Write a stored procedure to automatically pre-create upcoming partition tables ahead of ingestion.
  5. Write a rolling retention cleanup function to drop or archive partitions older than {{retention_months}} months.
  6. Incorporate table-level compression directives using {{compression_algorithm}} on detached historical partitions.
  7. Include transactional safety checks and idempotent execution wrappers.

Constraints

  • MUST output fully executable, dialect-specific code for {{rdbms_flavor}}.
  • MUST NOT lock parent tables during partition creation or drop phases.
  • All database objects must follow clean snake_case naming conventions.
  • Stored procedures must include embedded error handling and logging statements.

Output format

Provide the script structured in these exact blocks:

  • Section 1: Schema and Partitioned Table DDL (with indexes)
  • Section 2: Automated Partition Provisioning Stored Procedure
  • Section 3: Retention and Archival Cleanup Procedure
  • Section 4: Scheduled Cron/Job Invocation Example
  • Section 5: Rollback Script Total output length should be between 70 and 120 lines of commented SQL.

Self-review

  1. Confirm that interval bounds match {{partition_cadence}} without timestamp gaps.
  2. Verify that drop logic strictly enforces {{retention_months}} retention.
  3. Ensure syntax is 100% compliant with {{rdbms_flavor}}.
AuraScore breakdown
83/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency7/10 · Adequate

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-databases
energy-utilities
sql
timeseries
smartmeter