Skip to main content

delete_history_range

Delete historical data by time range (DeleteRawModifiedDetails).

Regulatory Requirements

Data deletion is a highly sensitive operation; most industry regulations (GMP / FDA / ISO) require that data be "never deleted" or that "deletion must be auditable." Server-side implementations may include additional safeguards.

Signature​

pub fn Session::delete_history_range(
&self,
node_id: &str,
start: SystemTime,
end: SystemTime,
delete_modified_too: bool,
) -> Result<StatusCode, OpcUaError>;
ParametersNote
node_idObjective NodeId
start / endDelete Range (UTC)
delete_modified_tootrue = Delete both the original and the modification history; false = Delete only the original and retain the modification history

Usage​

use std::time::{Duration, SystemTime};

let now = SystemTime::now();
let one_month_ago = now - Duration::from_secs(30 * 86400);
let one_week_ago = now - Duration::from_secs(7 * 86400);

// Delete data from one month to one week ago (retain modification records)
let st = s.delete_history_range(
"ns=2;s=Temperature",
one_month_ago, one_week_ago,
false,
)?;

if !st.is_good() {
eprintln!("Delete failed: {}", st);
}

Delete and modify records simultaneously​

When permitted by regulations, use delete_modified_too: true to clear everything at once (minimal space usage, but audit trail is lost):

s.delete_history_range(
"ns=2;s=Temperature",
one_month_ago, one_week_ago,
true,
)?;

Delete at a Specified Time (DeleteAtTime)​

OPC UA also specifies DeleteAtTime (delete at discrete time points), but the SDK does not expose this as a separate API today. Usage: Proceed update_history(node_id, HistoryUpdateType::Remove, &dvs), dvs where each DataValue in source_timestamp is treated as a time point to be deleted.

Delete Events (DeleteEvents)​

EventId Deleting events by list is currently SDK not directly supported (to be added in future versions). Workaround: Implement Session::call(...) this using a custom server-side method.

Regulatory Constraints​

Data deletion is a highly sensitive operation; most industry regulations (GMP / FDA / ISO) require:

  • Never Delete (Only "obsolete" tags allowed)
  • Deletions must be logged for auditing purposes (who deleted it, when, and why).

The server-side implementation may include additional safeguards. The client may receive BAD_USER_ACCESS_DENIED.

Performance​

  • The server may be blocked for an extended period during a large-range DELETE operation. The duration varies depending on the server and the range size; the timeout/wait time should be set based on actual server performance tests.
  • For operations that take a long time, it is recommended to execute them in a separate thread to avoid blocking the main process.

Error​

StatusCodeReason
BAD_HISTORY_OPERATION_UNSUPPORTEDThe server does not allow deletion.
BAD_USER_ACCESS_DENIEDNo permission
INVALID_ARGUMENTnode_id contains NUL

start >= end The client does not validate the data; it is sent directly to the server. The server decides whether to reject it.

Next Step​