Delete data from database (influxdb)

Author: Lukas Hörtnagl
Last update: 11 Mar 2025

Imports#

import warnings
from datetime import datetime

import dbc_influxdb as dbc

warnings.simplefilter("ignore")

Connect to database#

# Folder with configurations
DIRCONF = r'F:\Sync\luhk_work\20 - CODING\22 - POET\configs'  

# Instantiate class
dbc = dbc.dbcInflux(dirconf=DIRCONF)
Reading configuration files was successful.
Connection to database works.

Docstring#

# help(dbc.delete)

Delete specific variables#

BUCKET = f'ch-lae_processed'
DATA_VERSION = 'meteoscreening_diive'
MEASUREMENTS = ['PREC']  # Measurement name(s)
FIELDS = ['PREC_NABEL_TOT_T1_27_1']  # Variable name(s); InfluxDB stores variable names as '_field'
START = '2000-01-01 00:00:01'  # Delete data starting with this date
STOP = '2099-01-01 00:00:01'  # Delete data before this date (the stop date itself is not included)
TIMEZONE_OFFSET_TO_UTC_HOURS = 1  # Timezone, e.g. "1" is translated to timezone "UTC+01:00" (CET, winter time)

# Delete
dbc.delete(
    bucket=BUCKET,
    measurements=MEASUREMENTS,
    fields=FIELDS,
    start=START,
    stop=STOP,
    timezone_offset_to_utc_hours=TIMEZONE_OFFSET_TO_UTC_HOURS,
    data_version=DATA_VERSION
)
Deleted variables ['PREC_NABEL_TOT_T1_27_1'] between 2000-01-01T00:00:01+01:00 and 2099-01-01T00:00:01+01:00 from measurements ['PREC'] in bucket ch-lae_processed.

Delete all data of a specific data version#

# # Settings
# BUCKET = f'a'
# DATA_VERSION = 'meteoscreening_mst'
# DIRCONF = r'L:\Sync\luhk_work\20 - CODING\22 - POET\configs'  # Folder with configurations
# MEASUREMENTS = True
# FIELDS = True
# START = '2021-01-01 00:00:01'  # Delete data starting with this date
# STOP = '2022-01-01 00:00:01'  # Delete data before this date (the stop date itself is not included)
# TIMEZONE_OFFSET_TO_UTC_HOURS = 1  # Timezone, e.g. "1" is translated to timezone "UTC+01:00" (CET, winter time)

# # Delete
# dbc.delete(
#     bucket=BUCKET,
#     measurements=MEASUREMENTS,
#     fields=FIELDS,
#     start=START,
#     stop=STOP,
#     timezone_offset_to_utc_hours=TIMEZONE_OFFSET_TO_UTC_HOURS,
#     data_version=DATA_VERSION
# )

End of notebook.#

Congratulations, you reached the end of this notebook! Before you go let’s store your finish time.

dt_string = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"Finished. {dt_string}")
Finished. 2025-05-19 15:48:17