Skip to content

Instantly share code, notes, and snippets.

@msdousti
Created December 4, 2023 13:48
Show Gist options
  • Save msdousti/fc3f96c8e925506017628fd7321dddc2 to your computer and use it in GitHub Desktop.
Save msdousti/fc3f96c8e925506017628fd7321dddc2 to your computer and use it in GitHub Desktop.
create table my_outbox
(
id serial,
data jsonb not null,
created timestamp with time zone default now() not null,
primary key (id, created)
);
insert into my_outbox (data, created)
values ('{"a": 1}'::jsonb, default),
('{"a": 2}'::jsonb, now() - interval '10 days');
create extension if not exists timescaledb;
select create_hypertable(relation =>'my_outbox',
time_column_name => 'created',
chunk_time_interval => interval '1 day',
migrate_data => true);
-- select show_chunks('my_outbox');
SELECT add_retention_policy('my_outbox', interval '7 days');
-- select * from timescaledb_information.jobs where proc_name = 'policy_retention';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment