historian(sqlserver): retention / purge for hist.Sample and hist.Event #667
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The SQL Server historian backend (
Driver.Historian.SqlServer, schemahist) has no retention or purge, sohist.Sampleandhist.Eventgrow without bound.Scope: configurable retention (for example
ServerHistorian:SqlServer:RetentionDays), applied by a Primary-only background purge in batched deletes on the clustered key, so the log doesn't blow up. Consider partition switching for large installs, and add a metric for rows purged.Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
Implemented in
b3db64af, live-gate fix984e069f(both merged to master).ServerHistorian:SqlServer:RetentionDays(null = keep forever) +PurgeInterval(1 h) +PurgeBatchSize(4000).HistorianRetentionServicepurgeshist.Sampleper tag inDELETE TOP(n)batches on the clustered key andhist.Eventby time; cutoff on source time. Primary-gated onIHistorizationRoleView; one purger per database viasp_getapplock(timeout 0 — a loser skips the pass). Metricotopcua.historian.retention.purged{table}. OptionalIHistorianBackendProvider.CreateRetention(default null; QuestDB keeps its TTL). Since #668 it also purgeshist.SampleModified.sp_reset_connection, so a failed release clears the pool.Live gates (docker-dev): gate 1 — purge runs, rows below cutoff removed, counter emitted. Gate 1 found F3 (the skipped-pass path logged a false
sp_releaseapplockWarning and cleared the pool every pass) → fixed984e069f(release only when acquired); gate 2 re-gate PASS — applock held from an outside session for 80 s: only the Information "purge skipped" line, no Warning, no pool clear; purging resumed when released.Follow-up filed: cancel-between-batches release path not independently proven.