by eatonphil · 4y ago · 0 comments
Something like:
CREATE TABLE logs (
time TIMESTAMPTZ,
data JSONB
) PARTITION ON time IN INTERVAL '1 day'
And it just creates/manages these partitions for every day?If you can already manage partitions like this manually it feels like the next step is to just have it be automatic. So you have less of a need to switch to Timescale or ClickHouse or whatever other database as the amount of data you're storing/querying grows. (Yeah that's a handwave-y suggestion but at least you could stick with Postgres for longer.)
- https://github.com/pgpartman/pg_partman
- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Postg...
It's a great extension. We have used it in production for a few years now, as part of a commercial on-prem observability tool (an app that keeps around 1TB of data at any one time, written at avg 15mb/sec, maybe 500ish partitions, user configurable retention strategy). It is extremely reliable. Support for Keith F working on it is one of the reasons I like Crunchy.
edit: I clearly didn't read the link before writing this
TSL is mainly about not competing with their cloud offerings. So you can't run a database-as-a-service for time series data with it.
More about the license: https://www.timescale.com/blog/building-open-source-business...
Comparison about the open source and community editions: https://docs.timescale.com/timescaledb/latest/timescaledb-ed...
It’s as easy as:
CREATE EXTENSION timescaledb:
SELECT create_hypertable('table_name', 'time_column_name', chunk_time_interval=>interval '1 day'):
Disclaimer: I’m a Timescaler CREATE TABLE business_data (
customer_key TEXT,
data JSONB
) PARTITION ON customer_key
where it creates a partition for each unique value of customer_key. Seems like this ought not to be that hard.CREATE TABLE … PARTITION OF … FOR VALUES IN ('the_customer');
https://www.postgresql.org/docs/current/ddl-partitioning.htm...
However if you really want to go down this road, you could put a trigger on the main customer table for INSERT or UPDATE to run a SECURITY DEFINED (setuid) function that runs a CREATE TABLE … IF NOT EXISTS DDL query to your specifications. Just beware of corner cases and be extremely careful regarding secure access to modifications of that customers table.