Change bgw_job catalog table to enable custom jobs

This patch adds the columns required for custom jobs to the bgw_job
catalog table.
This commit is contained in:
Sven Klemm 2020-07-20 18:26:20 +02:00 committed by Sven Klemm
parent 6b62ed543c
commit 2f2e5ae68b
21 changed files with 302 additions and 143 deletions

View File

@ -195,9 +195,15 @@ CREATE TABLE IF NOT EXISTS _timescaledb_config.bgw_job (
job_type NAME NOT NULL,
schedule_interval INTERVAL NOT NULL,
max_runtime INTERVAL NOT NULL,
max_retries INT NOT NULL,
max_retries INTEGER NOT NULL,
retry_period INTERVAL NOT NULL,
CONSTRAINT valid_job_type CHECK (job_type IN ('telemetry_and_version_check_if_enabled', 'reorder', 'drop_chunks', 'continuous_aggregate', 'compress_chunks'))
proc_name NAME NOT NULL DEFAULT '',
proc_schema NAME NOT NULL DEFAULT '',
owner NAME NOT NULL DEFAULT CURRENT_ROLE,
scheduled BOOL NOT NULL DEFAULT true,
hypertable_id INTEGER REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE,
config JSONB,
CONSTRAINT valid_job_type CHECK (job_type IN ('telemetry_and_version_check_if_enabled', 'reorder', 'drop_chunks', 'continuous_aggregate', 'compress_chunks', 'custom'))
);
ALTER SEQUENCE _timescaledb_config.bgw_job_id_seq OWNED BY _timescaledb_config.bgw_job.id;

View File

@ -117,3 +117,18 @@ ALTER TABLE IF EXISTS _timescaledb_catalog.compression_chunk_size ADD COLUMN IF
--rewrite catalog table to not break catalog scans on tables with missingval optimization
CLUSTER _timescaledb_catalog.compression_chunk_size USING compression_chunk_size_pkey;
ALTER TABLE _timescaledb_catalog.compression_chunk_size SET WITHOUT CLUSTER;
ALTER TABLE _timescaledb_config.bgw_job ADD COLUMN proc_name NAME NOT NULL DEFAULT '';
ALTER TABLE _timescaledb_config.bgw_job ADD COLUMN proc_schema NAME NOT NULL DEFAULT '';
ALTER TABLE _timescaledb_config.bgw_job ADD COLUMN owner NAME NOT NULL DEFAULT CURRENT_ROLE;
ALTER TABLE _timescaledb_config.bgw_job ADD COLUMN scheduled BOOL NOT NULL DEFAULT true;
ALTER TABLE _timescaledb_config.bgw_job ADD COLUMN hypertable_id INTEGER REFERENCES _timescaledb_catalog.hypertable(id) ON DELETE CASCADE;
ALTER TABLE _timescaledb_config.bgw_job ADD COLUMN config JSONB;
ALTER TABLE _timescaledb_config.bgw_job DROP CONSTRAINT valid_job_type;
ALTER TABLE _timescaledb_config.bgw_job ADD CONSTRAINT valid_job_type CHECK (job_type IN ('telemetry_and_version_check_if_enabled', 'reorder', 'drop_chunks', 'continuous_aggregate', 'compress_chunks', 'custom'));
--rewrite catalog table to not break catalog scans on tables with missingval optimization
CLUSTER _timescaledb_config.bgw_job USING bgw_job_pkey;
ALTER TABLE _timescaledb_config.bgw_job SET WITHOUT CLUSTER;

View File

@ -20,6 +20,7 @@
#include <storage/procarray.h>
#include <storage/sinvaladt.h>
#include <utils/elog.h>
#include <utils/jsonb.h>
#include "job.h"
#include "scanner.h"
@ -184,16 +185,33 @@ get_job_type_from_name(Name job_type_name)
}
static BgwJob *
bgw_job_from_tuple(HeapTuple tuple, size_t alloc_size, MemoryContext mctx)
bgw_job_from_tuple(TupleInfo *ti, size_t alloc_size)
{
BgwJob *job;
bool isnull;
MemoryContext old_ctx;
Datum value;
/*
* allow for embedding with arbitrary alloc_size, which means we can't use
* the STRUCT_FROM_TUPLE macro
*/
Assert(alloc_size >= sizeof(BgwJob));
job = (BgwJob *) ts_create_struct_from_tuple(tuple, mctx, alloc_size, sizeof(FormData_bgw_job));
job = (BgwJob *) MemoryContextAllocZero(ti->mctx, alloc_size);
memcpy(job, GETSTRUCT(ti->tuple), sizeof(FormData_bgw_job));
/*
* GETSTRUCT does not work with variable length types and NULLs so we have
* to do special handling for hypertable_id and the jsonb column
*/
value = heap_getattr(ti->tuple, Anum_bgw_job_hypertable_id, ti->desc, &isnull);
job->fd.hypertable_id = isnull ? 0 : DatumGetInt32(value);
value = heap_getattr(ti->tuple, Anum_bgw_job_config, ti->desc, &isnull);
old_ctx = MemoryContextSwitchTo(ti->mctx);
job->fd.config = isnull ? NULL : DatumGetJsonbP(value);
MemoryContextSwitchTo(old_ctx);
job->bgw_type = get_job_type_from_name(&job->fd.job_type);
return job;
@ -209,7 +227,7 @@ static ScanTupleResult
bgw_job_accum_tuple_found(TupleInfo *ti, void *data)
{
AccumData *list_data = data;
BgwJob *job = bgw_job_from_tuple(ti->tuple, list_data->alloc_size, ti->mctx);
BgwJob *job = bgw_job_from_tuple(ti, list_data->alloc_size);
MemoryContext orig = MemoryContextSwitchTo(ti->mctx);
list_data->list = lappend(list_data->list, job);
@ -300,8 +318,7 @@ ts_bgw_job_find_with_lock(int32 bgw_job_id, MemoryContext mctx, LOCKMODE tuple_l
ts_scanner_foreach(&iterator)
{
HeapTuple heap = ts_scan_iterator_tuple(&iterator);
job = bgw_job_from_tuple(heap, sizeof(BgwJob), mctx);
job = bgw_job_from_tuple(ts_scan_iterator_tuple_info(&iterator), sizeof(BgwJob));
Assert(num_found == 0);
num_found++;
@ -356,7 +373,7 @@ ts_bgw_job_find(int32 bgw_job_id, MemoryContext mctx, bool fail_if_not_found)
ts_scanner_foreach(&iterator)
{
Assert(num_found == 0);
job = bgw_job_from_tuple(ts_scan_iterator_tuple(&iterator), sizeof(BgwJob), mctx);
job = bgw_job_from_tuple(ts_scan_iterator_tuple_info(&iterator), sizeof(BgwJob));
num_found++;
}
@ -792,7 +809,9 @@ ts_bgw_job_run_and_set_next_start(BgwJob *job, job_main_func func, int64 initial
int
ts_bgw_job_insert_relation(Name application_name, Name job_type, Interval *schedule_interval,
Interval *max_runtime, int32 max_retries, Interval *retry_period)
Interval *max_runtime, int32 max_retries, Interval *retry_period,
Name proc_name, Name proc_schema, Name owner, bool scheduled,
int32 hypertable_id, Jsonb *config)
{
Catalog *catalog = ts_catalog_get();
Relation rel;
@ -812,6 +831,20 @@ ts_bgw_job_insert_relation(Name application_name, Name job_type, Interval *sched
values[AttrNumberGetAttrOffset(Anum_bgw_job_max_retries)] = Int32GetDatum(max_retries);
values[AttrNumberGetAttrOffset(Anum_bgw_job_retry_period)] = IntervalPGetDatum(retry_period);
values[AttrNumberGetAttrOffset(Anum_bgw_job_proc_name)] = NameGetDatum(proc_name);
values[AttrNumberGetAttrOffset(Anum_bgw_job_proc_schema)] = NameGetDatum(proc_schema);
values[AttrNumberGetAttrOffset(Anum_bgw_job_owner)] = NameGetDatum(owner);
values[AttrNumberGetAttrOffset(Anum_bgw_job_scheduled)] = BoolGetDatum(scheduled);
if (hypertable_id == 0)
nulls[AttrNumberGetAttrOffset(Anum_bgw_job_hypertable_id)] = true;
else
values[AttrNumberGetAttrOffset(Anum_bgw_job_hypertable_id)] = Int32GetDatum(hypertable_id);
if (config == NULL)
nulls[AttrNumberGetAttrOffset(Anum_bgw_job_config)] = true;
else
values[AttrNumberGetAttrOffset(Anum_bgw_job_config)] = JsonbPGetDatum(config);
ts_catalog_database_info_become_owner(ts_catalog_database_info_get(), &sec_ctx);
values[AttrNumberGetAttrOffset(Anum_bgw_job_id)] =
ts_catalog_table_next_seq_id(catalog, BGW_JOB);

View File

@ -53,7 +53,9 @@ extern TSDLLEXPORT bool ts_bgw_job_delete_by_id(int32 job_id);
extern TSDLLEXPORT int32 ts_bgw_job_insert_relation(Name application_name, Name job_type,
Interval *schedule_interval,
Interval *max_runtime, int32 max_retries,
Interval *retry_period);
Interval *retry_period, Name proc_name,
Name proc_schema, Name owner, bool scheduled,
int32 hypertable_id, Jsonb *config);
extern TSDLLEXPORT void ts_bgw_job_update_by_id(int32 job_id, BgwJob *updated_job);
extern TSDLLEXPORT void ts_bgw_job_permission_check(BgwJob *job);

View File

@ -7,7 +7,7 @@
#define TIMESCALEDB_CATALOG_H
#include <postgres.h>
#include <utils/jsonb.h>
#include <utils/rel.h>
#include <nodes/nodes.h>
#include <access/heapam.h>
@ -649,6 +649,12 @@ enum Anum_bgw_job
Anum_bgw_job_max_runtime,
Anum_bgw_job_max_retries,
Anum_bgw_job_retry_period,
Anum_bgw_job_proc_name,
Anum_bgw_job_proc_schema,
Anum_bgw_job_owner,
Anum_bgw_job_scheduled,
Anum_bgw_job_hypertable_id,
Anum_bgw_job_config,
_Anum_bgw_job_max,
};
@ -663,6 +669,12 @@ typedef struct FormData_bgw_job
Interval max_runtime;
int32 max_retries;
Interval retry_period;
NameData proc_name;
NameData proc_schema;
NameData owner;
bool scheduled;
int32 hypertable_id;
Jsonb *config;
} FormData_bgw_job;
typedef FormData_bgw_job *Form_bgw_job;

View File

@ -18,7 +18,7 @@
static void ts_jsonb_add_pair(JsonbParseState *state, JsonbValue *key, JsonbValue *value);
TSDLLEXPORT void
void
ts_jsonb_add_bool(JsonbParseState *state, const char *key, bool boolean)
{
JsonbValue json_value;
@ -29,7 +29,7 @@ ts_jsonb_add_bool(JsonbParseState *state, const char *key, bool boolean)
ts_jsonb_add_value(state, key, &json_value);
}
TSDLLEXPORT void
void
ts_jsonb_add_str(JsonbParseState *state, const char *key, const char *value)
{
JsonbValue json_value;
@ -45,6 +45,24 @@ ts_jsonb_add_str(JsonbParseState *state, const char *key, const char *value)
ts_jsonb_add_value(state, key, &json_value);
}
void
ts_jsonb_add_int32(JsonbParseState *state, const char *key, const int32 int_value)
{
Numeric value;
value = DatumGetNumeric(DirectFunctionCall1(int4_numeric, Int32GetDatum(int_value)));
ts_jsonb_add_numeric(state, key, value);
}
void
ts_jsonb_add_numeric(JsonbParseState *state, const char *key, const Numeric value)
{
JsonbValue json_value = { .type = jbvNumeric, .val.numeric = value };
ts_jsonb_add_value(state, key, &json_value);
}
void
ts_jsonb_add_value(JsonbParseState *state, const char *key, JsonbValue *value)
{
@ -73,7 +91,7 @@ ts_jsonb_add_pair(JsonbParseState *state, JsonbValue *key, JsonbValue *value)
pushJsonbValue(&state, WJB_VALUE, value);
}
TSDLLEXPORT text *
text *
ts_jsonb_get_text_field(Jsonb *json, text *field_name)
{
/*
@ -96,7 +114,7 @@ ts_jsonb_get_text_field(Jsonb *json, text *field_name)
return DatumGetTextP(result);
}
TSDLLEXPORT char *
char *
ts_jsonb_get_str_field(Jsonb *license, text *field_name)
{
text *text_str = ts_jsonb_get_text_field(license, field_name);
@ -107,7 +125,7 @@ ts_jsonb_get_str_field(Jsonb *license, text *field_name)
return text_to_cstring(text_str);
}
TSDLLEXPORT TimestampTz
TimestampTz
ts_jsonb_get_time_field(Jsonb *license, text *field_name, bool *field_found)
{
Datum time_datum;
@ -127,3 +145,21 @@ ts_jsonb_get_time_field(Jsonb *license, text *field_name, bool *field_found)
*field_found = true;
return DatumGetTimestampTz(time_datum);
}
int32
ts_jsonb_get_int32_field(Jsonb *json, text *field_name, bool *field_found)
{
Datum int_datum;
char *int_str = ts_jsonb_get_str_field(json, field_name);
if (int_str == NULL)
{
*field_found = false;
return 0;
}
int_datum = DirectFunctionCall1(int4in, CStringGetDatum(int_str));
*field_found = true;
return DatumGetInt32(int_datum);
}

View File

@ -15,11 +15,17 @@
extern TSDLLEXPORT void ts_jsonb_add_bool(JsonbParseState *state, const char *key, bool boolean);
extern TSDLLEXPORT void ts_jsonb_add_str(JsonbParseState *state, const char *key,
const char *value);
extern TSDLLEXPORT void ts_jsonb_add_int32(JsonbParseState *state, const char *key,
const int32 value);
extern TSDLLEXPORT void ts_jsonb_add_numeric(JsonbParseState *state, const char *key,
const Numeric value);
extern void ts_jsonb_add_value(JsonbParseState *state, const char *key, JsonbValue *value);
extern TSDLLEXPORT text *ts_jsonb_get_text_field(Jsonb *json, text *field_name);
extern TSDLLEXPORT char *ts_jsonb_get_str_field(Jsonb *license, text *field_name);
extern TSDLLEXPORT TimestampTz ts_jsonb_get_time_field(Jsonb *license, text *field_name,
bool *field_found);
extern TSDLLEXPORT int32 ts_jsonb_get_int32_field(Jsonb *json, text *field_name, bool *field_found);
#endif /* TIMESCALEDB_JSONB_UTILS_H */

View File

@ -17,7 +17,7 @@ CREATE OR REPLACE FUNCTION ts_bgw_params_destroy() RETURNS VOID
AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION ts_bgw_params_reset_time(set_time BIGINT = 0, wait BOOLEAN = false) RETURNS VOID
AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION insert_job(application_name NAME, job_type NAME, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL)
CREATE OR REPLACE FUNCTION insert_job(application_name NAME, job_type NAME, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, proc_name NAME DEFAULT '', proc_schema NAME DEFAULT '', owner NAME DEFAULT '', hypertable_id INTEGER DEFAULT 0, scheduled BOOL DEFAULT true, config JSONB DEFAULT '{}')
RETURNS VOID
AS :MODULE_PATHNAME, 'ts_test_bgw_job_insert_relation'
LANGUAGE C VOLATILE STRICT;
@ -114,9 +114,9 @@ SELECT ts_bgw_params_reset_time();
INSERT INTO _timescaledb_config.bgw_job (application_name, job_type, schedule_INTERVAL, max_runtime, max_retries, retry_period) VALUES
('test_job_1', 'bgw_test_job_1', INTERVAL '100ms', INTERVAL '100s', 3, INTERVAL '1s');
select * from _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------+----------------+-------------------+-----------------+-------------+--------------
1000 | test_job_1 | bgw_test_job_1 | @ 0.1 secs | @ 1 min 40 secs | 3 | @ 1 sec
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------+----------------+-------------------+-----------------+-------------+--------------+-----------+-------------+------------+-----------+---------------+--------
1000 | test_job_1 | bgw_test_job_1 | @ 0.1 secs | @ 1 min 40 secs | 3 | @ 1 sec | | | super_user | t | |
(1 row)
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
@ -964,9 +964,9 @@ DELETE FROM _timescaledb_config.bgw_job;
INSERT INTO _timescaledb_config.bgw_job (application_name, job_type, schedule_INTERVAL, max_runtime, max_retries, retry_period) VALUES
('test_job_4', 'bgw_test_job_4', INTERVAL '100ms', INTERVAL '100s', 3, INTERVAL '1s');
select * from _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------+----------------+-------------------+-----------------+-------------+--------------
1014 | test_job_4 | bgw_test_job_4 | @ 0.1 secs | @ 1 min 40 secs | 3 | @ 1 sec
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------+----------------+-------------------+-----------------+-------------+--------------+-----------+-------------+------------+-----------+---------------+--------
1014 | test_job_4 | bgw_test_job_4 | @ 0.1 secs | @ 1 min 40 secs | 3 | @ 1 sec | | | super_user | t | |
(1 row)
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER

View File

@ -24,7 +24,7 @@ AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION ts_bgw_params_reset_time(set_time BIGINT = 0, wait BOOLEAN = false) RETURNS VOID
AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION insert_job(application_name NAME, job_type NAME, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL)
CREATE OR REPLACE FUNCTION insert_job(application_name NAME, job_type NAME, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, proc_name NAME DEFAULT '', proc_schema NAME DEFAULT '', owner NAME DEFAULT '', hypertable_id INTEGER DEFAULT 0, scheduled BOOL DEFAULT true, config JSONB DEFAULT '{}')
RETURNS VOID
AS :MODULE_PATHNAME, 'ts_test_bgw_job_insert_relation'
LANGUAGE C VOLATILE STRICT;

View File

@ -403,7 +403,13 @@ ts_test_bgw_job_insert_relation(PG_FUNCTION_ARGS)
PG_GETARG_INTERVAL_P(2),
PG_GETARG_INTERVAL_P(3),
PG_GETARG_INT32(4),
PG_GETARG_INTERVAL_P(5));
PG_GETARG_INTERVAL_P(5),
PG_GETARG_NAME(6),
PG_GETARG_NAME(7),
PG_GETARG_NAME(8),
PG_GETARG_BOOL(9),
PG_GETARG_INT32(10),
PG_GETARG_JSONB_P(11));
PG_RETURN_NULL();
}

View File

@ -60,6 +60,7 @@ compress_chunks_add_policy(PG_FUNCTION_ARGS)
{
NameData application_name;
NameData compress_chunks_name;
NameData proc_name, proc_schema, owner;
int32 job_id;
BgwPolicyCompressChunks *existing;
Oid ht_oid = PG_GETARG_OID(0);
@ -137,12 +138,22 @@ compress_chunks_add_policy(PG_FUNCTION_ARGS)
/* insert a new job into jobs table */
namestrcpy(&application_name, "Compress Chunks Background Job");
namestrcpy(&compress_chunks_name, "compress_chunks");
namestrcpy(&proc_name, "");
namestrcpy(&proc_schema, "");
namestrcpy(&owner, GetUserNameFromId(owner_id, false));
job_id = ts_bgw_job_insert_relation(&application_name,
&compress_chunks_name,
default_schedule_interval,
DEFAULT_MAX_RUNTIME,
DEFAULT_MAX_RETRIES,
DEFAULT_RETRY_PERIOD);
DEFAULT_RETRY_PERIOD,
&proc_name,
&proc_schema,
&owner,
true,
hypertable->fd.id,
NULL);
policy = (BgwPolicyCompressChunks){ .fd = {
.job_id = job_id,

View File

@ -5,14 +5,14 @@
*/
#include <postgres.h>
#include <access/xact.h>
#include <catalog/pg_type.h>
#include <miscadmin.h>
#include <utils/builtins.h>
#include <utils/lsyscache.h>
#include <utils/syscache.h>
#include <miscadmin.h>
#include <hypertable_cache.h>
#include <access/xact.h>
#include "bgw/job.h"
#include "bgw_policy/drop_chunks.h"
@ -188,12 +188,23 @@ drop_chunks_add_policy(PG_FUNCTION_ARGS)
/* Next, insert a new job into jobs table */
namestrcpy(&application_name, "Drop Chunks Background Job");
namestrcpy(&drop_chunks_name, "drop_chunks");
NameData proc_name, proc_schema, owner;
namestrcpy(&proc_name, "");
namestrcpy(&proc_schema, "");
namestrcpy(&owner, GetUserNameFromId(owner_id, false));
job_id = ts_bgw_job_insert_relation(&application_name,
&drop_chunks_name,
DEFAULT_SCHEDULE_INTERVAL,
DEFAULT_MAX_RUNTIME,
DEFAULT_MAX_RETRIES,
DEFAULT_RETRY_PERIOD);
DEFAULT_RETRY_PERIOD,
&proc_name,
&proc_schema,
&owner,
true,
meta.ht->fd.id,
NULL);
policy = (BgwPolicyDropChunks){
.job_id = job_id,

View File

@ -71,6 +71,7 @@ reorder_add_policy(PG_FUNCTION_ARGS)
{
NameData application_name;
NameData reorder_name;
NameData proc_name, proc_schema, owner;
int32 job_id;
BgwPolicyReorder *existing;
Dimension *dim;
@ -135,6 +136,9 @@ reorder_add_policy(PG_FUNCTION_ARGS)
/* Next, insert a new job into jobs table */
namestrcpy(&application_name, "Reorder Background Job");
namestrcpy(&reorder_name, "reorder");
namestrcpy(&proc_name, "");
namestrcpy(&proc_schema, "");
namestrcpy(&owner, GetUserNameFromId(owner_id, false));
/*
* Try to see if the hypertable has a specified chunk length for the
@ -159,7 +163,13 @@ reorder_add_policy(PG_FUNCTION_ARGS)
default_schedule_interval,
DEFAULT_MAX_RUNTIME,
DEFAULT_MAX_RETRIES,
DEFAULT_RETRY_PERIOD);
DEFAULT_RETRY_PERIOD,
&proc_name,
&proc_schema,
&owner,
true,
hypertable_id,
NULL);
/* Now, insert a new row in the reorder args table */
policy.fd.job_id = job_id;

View File

@ -4,7 +4,6 @@
* LICENSE-TIMESCALE for a copy of the license.
*/
#include <postgres.h>
#include <c.h>
#include <utils/builtins.h>
#include <hypertable_cache.h>
@ -66,6 +65,7 @@ ts_continuous_agg_job_add(int32 raw_table_id, int64 bucket_width, Interval *refr
{
NameData application_name;
NameData job_type;
NameData proc_name, proc_schema, owner;
int32 job_id;
namestrcpy(&job_type, "continuous_aggregate");
@ -75,12 +75,23 @@ ts_continuous_agg_job_add(int32 raw_table_id, int64 bucket_width, Interval *refr
refresh_interval =
continuous_agg_job_get_default_schedule_interval(raw_table_id, bucket_width);
namestrcpy(&proc_name, "");
namestrcpy(&proc_schema, "");
namestrcpy(&owner, "");
job_id = ts_bgw_job_insert_relation(&application_name,
&job_type,
refresh_interval,
DEFAULT_MAX_RUNTIME,
DEFAULT_MAX_RETRIES,
refresh_interval);
refresh_interval,
&proc_name,
&proc_schema,
&owner,
true,
0,
NULL);
return job_id;
}

View File

@ -63,9 +63,9 @@ select * from _timescaledb_config.bgw_policy_reorder where job_id=:reorder_job_i
(1 row)
select * from _timescaledb_config.bgw_job where job_type IN ('reorder');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
select job_id, chunk_id, num_times_job_run from _timescaledb_internal.bgw_policy_chunk_stats;

View File

@ -43,8 +43,8 @@ SELECT ts_bgw_params_create();
(1 row)
SELECT * FROM _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
SELECT * FROM timescaledb_information.drop_chunks_policies;
@ -108,9 +108,9 @@ select * from _timescaledb_config.bgw_policy_reorder where job_id=:reorder_job_i
-- job was created
SELECT * FROM _timescaledb_config.bgw_job where id=:reorder_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
-- no stats
@ -144,9 +144,9 @@ SELECT * FROM sorted_bgw_log;
(2 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:reorder_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
-- job ran once, successfully
@ -184,9 +184,9 @@ SELECT * FROM sorted_bgw_log;
(4 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:reorder_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
-- two runs
@ -228,9 +228,9 @@ SELECT * FROM sorted_bgw_log;
(6 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:reorder_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
SELECT *
@ -272,9 +272,9 @@ SELECT * FROM sorted_bgw_log;
(7 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:reorder_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 4 days | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
SELECT *
@ -322,8 +322,8 @@ select * from _timescaledb_config.bgw_policy_reorder where job_id=:reorder_job_i
(0 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:reorder_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
SELECT job_id, next_start, last_finish as until_next, last_run_success, total_runs, total_successes, total_failures, total_crashes
@ -353,8 +353,8 @@ SELECT * FROM sorted_bgw_log;
(8 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:reorder_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
-- still only 3 chunks clustered
@ -438,9 +438,9 @@ select * from _timescaledb_config.bgw_policy_drop_chunks where job_id=:drop_chun
(1 row)
SELECT * FROM _timescaledb_config.bgw_job where id=:drop_chunks_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 2 |
(1 row)
-- no stats
@ -477,9 +477,9 @@ SELECT * FROM sorted_bgw_log;
(2 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:drop_chunks_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 2 |
(1 row)
-- job ran once, successfully
@ -516,9 +516,9 @@ SELECT * FROM sorted_bgw_log;
(3 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:drop_chunks_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 2 |
(1 row)
-- still only 1 run
@ -568,9 +568,9 @@ SELECT * FROM sorted_bgw_log;
(6 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:drop_chunks_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 2 |
(1 row)
-- 2 runs
@ -646,9 +646,9 @@ SELECT * FROM sorted_bgw_log;
(9 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:drop_chunks_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | 0 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1001 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | 0 | @ 5 mins | | | default_perm_user | t | 2 |
(1 row)
-- should now have a failure

View File

@ -93,9 +93,9 @@ select * from _timescaledb_config.bgw_policy_drop_chunks where job_id=:drop_chun
(1 row)
SELECT * FROM _timescaledb_config.bgw_job where id=:drop_chunks_job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1000 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Drop Chunks Background Job | drop_chunks | @ 1 sec | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
--turn on compression and compress all chunks

View File

@ -54,9 +54,9 @@ select job_id as compressjob_id, hypertable_id, older_than from _timescaledb_con
\gset
select * from _timescaledb_config.bgw_job where job_type like 'compress%';
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+--------------------------------+-----------------+--------------------+-------------+-------------+--------------
1000 | Compress Chunks Background Job | compress_chunks | @ 15 days 12 hours | @ 0 | -1 | @ 1 hour
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+--------------------------------+-----------------+--------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Compress Chunks Background Job | compress_chunks | @ 15 days 12 hours | @ 0 | -1 | @ 1 hour | | | default_perm_user | t | 1 |
(1 row)
select * from alter_job_schedule(:compressjob_id, schedule_interval=>'1s');
@ -66,9 +66,9 @@ select * from alter_job_schedule(:compressjob_id, schedule_interval=>'1s');
(1 row)
select * from _timescaledb_config.bgw_job where job_type like 'compress%';
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+--------------------------------+-----------------+-------------------+-------------+-------------+--------------
1000 | Compress Chunks Background Job | compress_chunks | @ 1 sec | @ 0 | -1 | @ 1 hour
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+--------------------------------+-----------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Compress Chunks Background Job | compress_chunks | @ 1 sec | @ 0 | -1 | @ 1 hour | | | default_perm_user | t | 1 |
(1 row)
insert into conditions

View File

@ -12,8 +12,8 @@ AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
DELETE FROM _timescaledb_config.bgw_job WHERE TRUE;
SET ROLE :ROLE_DEFAULT_PERM_USER;
SELECT * FROM _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
--TEST1 ---
@ -50,9 +50,9 @@ from foo
group by time_bucket(1, a), a;
NOTICE: adding index _materialized_hypertable_2_a_time_partition_col_idx ON _timescaledb_internal._materialized_hypertable_2 USING BTREE(a, time_partition_col)
SELECT * FROM _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------
1000 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
1000 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours | | | | t | |
(1 row)
SELECT ca.raw_hypertable_id as "RAW_HYPERTABLE_ID",
@ -94,8 +94,8 @@ SET ROLE :ROLE_DEFAULT_PERM_USER;
drop view mat_m1 cascade;
NOTICE: drop cascades to table _timescaledb_internal._hyper_2_2_chunk
SELECT * FROM _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
CREATE TABLE conditions (
@ -817,8 +817,8 @@ select count(*) from _timescaledb_catalog.continuous_aggs_materialization_invali
(1 row)
SELECT * FROM _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
--mat table, user_view, and partial view all gone

View File

@ -53,8 +53,8 @@ SELECT ts_bgw_params_create();
(1 row)
SELECT * FROM _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
SELECT * FROM timescaledb_information.policy_stats;
@ -107,9 +107,9 @@ SELECT mat_hypertable_id, user_view_schema, user_view_name, bucket_width, job_i
SELECT job_id FROM _timescaledb_catalog.continuous_agg \gset
-- job was created
SELECT * FROM _timescaledb_config.bgw_job where id=:job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------
1000 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
1000 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours | | | | t | |
(1 row)
-- create 10 time buckets
@ -145,9 +145,9 @@ SELECT * FROM sorted_bgw_log;
(2 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------
1000 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
1000 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours | | | | t | |
(1 row)
-- job ran once, successfully
@ -432,9 +432,9 @@ SELECT * FROM sorted_bgw_log;
(6 rows)
SELECT * FROM _timescaledb_config.bgw_job where id=:job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------
1001 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+-------------------------------------+----------------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
1001 | Continuous Aggregate Background Job | continuous_aggregate | @ 12 hours | @ 0 | -1 | @ 12 hours | | | | t | |
(1 row)
-- job ran again, fast restart

View File

@ -97,18 +97,18 @@ select add_reorder_policy('test_table2', 'test_table2_time_idx');
(1 row)
select * from _timescaledb_config.bgw_job where job_type IN ('drop_chunks', 'reorder');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
1001 | Reorder Background Job | reorder | @ 12 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
1001 | Reorder Background Job | reorder | @ 12 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 3 |
(2 rows)
DROP TABLE test_table2;
-- Make sure that test_table2 reorder policy gets dropped
select * from _timescaledb_config.bgw_job where job_type IN ('drop_chunks', 'reorder');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1000 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1000 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(1 row)
-- Error whenever incorrect arguments are applied (must have table and interval)
@ -356,8 +356,8 @@ ERROR: cannot remove reorder policy, no such policy exists
\set ON_ERROR_STOP 1
-- Now make sure policy args have correct job deletion dependency
select * from _timescaledb_config.bgw_job where job_type IN ('drop_chunks', 'reorder');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
select add_drop_chunks_policy('test_table', INTERVAL '2 month') as job_id \gset
@ -459,11 +459,11 @@ select count(*) from _timescaledb_config.bgw_policy_reorder where job_id=:reorde
(1 row)
select * from _timescaledb_config.bgw_job;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+----------------------------------------+-------------------+-----------------+-------------+--------------
1 | Telemetry Reporter | telemetry_and_version_check_if_enabled | @ 24 hours | @ 1 min 40 secs | -1 | @ 1 hour
1007 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins
1008 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+----------------------------------------+-------------------+-----------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1 | Telemetry Reporter | telemetry_and_version_check_if_enabled | @ 24 hours | @ 1 min 40 secs | -1 | @ 1 hour | | | super_user | t | |
1007 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 1 |
1008 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 1 |
(3 rows)
DROP TABLE test_table;
@ -532,10 +532,10 @@ select add_drop_chunks_policy('test_table2', INTERVAL '1 days');
(1 row)
select * from _timescaledb_config.bgw_job where job_type IN ('drop_chunks');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1009 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins
1010 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1009 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 4 |
1010 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 5 |
(2 rows)
select * from _timescaledb_config.bgw_policy_drop_chunks;
@ -548,9 +548,9 @@ select * from _timescaledb_config.bgw_policy_drop_chunks;
DROP TABLE test_table;
DROP TABLE test_table_int;
select * from _timescaledb_config.bgw_job where job_type IN ('drop_chunks');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1010 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1010 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 5 |
(1 row)
select * from _timescaledb_config.bgw_policy_drop_chunks;
@ -561,8 +561,8 @@ select * from _timescaledb_config.bgw_policy_drop_chunks;
DROP TABLE test_table2;
select * from _timescaledb_config.bgw_job where job_type IN ('drop_chunks');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
select * from _timescaledb_config.bgw_policy_drop_chunks;
@ -626,9 +626,9 @@ select job_id,chunk_id,num_times_job_run from _timescaledb_internal.bgw_policy_c
(1 row)
select * from _timescaledb_config.bgw_job where job_type='reorder';
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1011 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1011 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 6 |
(1 row)
-- Deleting a chunk that has nothing to do with the job should do nothing
@ -642,9 +642,9 @@ select job_id,chunk_id,num_times_job_run from _timescaledb_internal.bgw_policy_c
(1 row)
select * from _timescaledb_config.bgw_job where job_type='reorder';
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1011 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1011 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 6 |
(1 row)
-- Dropping the hypertable should drop the chunk, which should drop the reorder policy
@ -655,8 +655,8 @@ select job_id,chunk_id,num_times_job_run from _timescaledb_internal.bgw_policy_c
(0 rows)
select * from _timescaledb_config.bgw_job where job_type='reorder';
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
-- Now check dropping a job will drop the chunk_stat row
@ -688,10 +688,10 @@ select job_id,chunk_id,num_times_job_run from _timescaledb_internal.bgw_policy_c
(1 row)
select * from _timescaledb_config.bgw_job where job_type in ('drop_chunks', 'reorder');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+----------------------------+-------------+-------------------+-------------+-------------+--------------
1012 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
1013 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+----------------------------+-------------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1012 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 7 |
1013 | Drop Chunks Background Job | drop_chunks | @ 1 day | @ 5 mins | -1 | @ 5 mins | | | default_perm_user | t | 7 |
(2 rows)
-- Dropping the drop_chunks job should not affect the chunk_stats row
@ -708,9 +708,9 @@ select job_id,chunk_id,num_times_job_run from _timescaledb_internal.bgw_policy_c
(1 row)
select * from _timescaledb_config.bgw_job where job_type in ('drop_chunks', 'reorder');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1012 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1012 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 7 |
(1 row)
select remove_reorder_policy('test_table');
@ -726,16 +726,16 @@ select job_id,chunk_id,num_times_job_run from _timescaledb_internal.bgw_policy_c
(0 rows)
select * from _timescaledb_config.bgw_job where job_type in ('drop_chunks', 'reorder');
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
----+------------------+----------+-------------------+-------------+-------------+--------------
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
----+------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------+-----------+---------------+--------
(0 rows)
-- Now test if alter_job_schedule works
select add_reorder_policy('test_table', 'test_table_time_idx') as job_id \gset
select * from _timescaledb_config.bgw_job where id=:job_id;
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period
------+------------------------+----------+-------------------+-------------+-------------+--------------
1014 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins
id | application_name | job_type | schedule_interval | max_runtime | max_retries | retry_period | proc_name | proc_schema | owner | scheduled | hypertable_id | config
------+------------------------+----------+-------------------+-------------+-------------+--------------+-----------+-------------+-------------------+-----------+---------------+--------
1014 | Reorder Background Job | reorder | @ 84 hours | @ 0 | -1 | @ 5 mins | | | default_perm_user | t | 7 |
(1 row)
-- No change