I'm monitoring, collecting and storing event data for different organizations in my TimescaleDB.
I have a TimescaleDB with one database. Each organization has its own schema in that database. Each schema has two tables: A device table and an event table.
The device table stores information about the devices of the given organization, while the event table is a Time Series table that stores all the events collected from the different devices. The event table has a column (foreign key) that points to the device table.
This is how my database is structured
▼ Servers (1)
▼ TimescaleDB Cloud
▼ Databases (1)
▼ myTimescaleDB
▼ Schemas (12)
▼ organization_1 (12)
▼ Tables (2)
▼ device
▼ Columns (3)
device_id
device_name
device_type
▼ event
▼ Columns (5)
event_id
time
device_id (fk)
event_source
event_type
▼ organization_2 (12)
▼ Tables (2)
▼ device
▼ Columns (3)
device_id
device_name
device_type
▼ event
▼ Columns (5)
event_id
time
device_id (fk)
event_source
event_type
I want to create a scheduled user-defined action that basically makes sure that each device only has a maximum of 10.000 events. So every - let's say 5 minutes - the user-defined action should count the number of events of each device in each schema. Any device that has more than 10.000 events should be trimmed to only have 10.000. We always want to trim the old events though. How do I do this?