mirror of
https://github.com/timescale/timescaledb.git
synced 2025-04-20 03:21:15 +08:00
Block unlogged tables from being used as hypertables
This commit is contained in:
parent
a8c637e112
commit
8bf552e2ad
@ -824,6 +824,12 @@ table_has_tuples(Oid table_relid, LOCKMODE lockmode)
|
||||
return hastuples;
|
||||
}
|
||||
|
||||
static bool
|
||||
table_is_logged(Oid table_relid)
|
||||
{
|
||||
return get_rel_persistence(table_relid) == RELPERSISTENCE_PERMANENT;
|
||||
}
|
||||
|
||||
bool
|
||||
hypertable_has_tuples(Oid table_relid, LOCKMODE lockmode)
|
||||
{
|
||||
@ -1039,6 +1045,12 @@ hypertable_create(PG_FUNCTION_ARGS)
|
||||
errmsg("table \"%s\" is already partitioned", get_rel_name(table_relid)),
|
||||
errdetail("It is not possible to turn tables that use inheritance into hypertables.")));
|
||||
|
||||
if (!table_is_logged(table_relid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("table \"%s\" has to be logged", get_rel_name(table_relid)),
|
||||
errdetail("It is not possible to turn temporary or unlogged tables into hypertables.")));
|
||||
|
||||
/*
|
||||
* Create the associated schema where chunks are stored, or, check
|
||||
* permissions if it already exists
|
||||
|
@ -1571,6 +1571,11 @@ process_altertable_end_subcmd(Hypertable *ht, Node *parsetree, ObjectAddress *ob
|
||||
case AT_ClusterOn:
|
||||
process_altertable_clusteron_end(ht, cmd);
|
||||
break;
|
||||
case AT_SetUnLogged:
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("logging cannot be turned off for hypertables")));
|
||||
break;
|
||||
case AT_SetRelOptions:
|
||||
case AT_ResetRelOptions:
|
||||
case AT_ReplaceRelOptions:
|
||||
@ -1587,6 +1592,7 @@ process_altertable_end_subcmd(Hypertable *ht, Node *parsetree, ObjectAddress *ob
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("hypertables do not support inheritance")));
|
||||
case AT_SetStatistics:
|
||||
case AT_SetLogged:
|
||||
/* handled by default recursion */
|
||||
break;
|
||||
default:
|
||||
|
@ -53,3 +53,31 @@ ERROR: table "Parent" is already partitioned
|
||||
SELECT * FROM create_hypertable('"public"."Child"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
ERROR: table "Child" is already partitioned
|
||||
\set ON_ERROR_STOP 1
|
||||
CREATE UNLOGGED TABLE PUBLIC."Hypertable_unlogged" (
|
||||
time BIGINT NOT NULL,
|
||||
"Device_id" TEXT NOT NULL,
|
||||
temp_c int NOT NULL DEFAULT -1
|
||||
);
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_unlogged"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
ERROR: table "Hypertable_unlogged" has to be logged
|
||||
\set ON_ERROR_STOP 1
|
||||
ALTER TABLE PUBLIC."Hypertable_unlogged" SET LOGGED;
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_unlogged"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
create_hypertable
|
||||
-------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TEMP TABLE "Hypertable_temp" (
|
||||
time BIGINT NOT NULL,
|
||||
"Device_id" TEXT NOT NULL,
|
||||
temp_c int NOT NULL DEFAULT -1
|
||||
);
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"Hypertable_temp"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
ERROR: table "Hypertable_temp" has to be logged
|
||||
ALTER TABLE "Hypertable_1" SET UNLOGGED;
|
||||
ERROR: logging cannot be turned off for hypertables
|
||||
\set ON_ERROR_STOP 1
|
||||
ALTER TABLE "Hypertable_1" SET LOGGED;
|
||||
|
@ -48,3 +48,30 @@ CREATE TABLE PUBLIC."Child" () INHERITS ("Parent");
|
||||
SELECT * FROM create_hypertable('"public"."Parent"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
SELECT * FROM create_hypertable('"public"."Child"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
\set ON_ERROR_STOP 1
|
||||
|
||||
CREATE UNLOGGED TABLE PUBLIC."Hypertable_unlogged" (
|
||||
time BIGINT NOT NULL,
|
||||
"Device_id" TEXT NOT NULL,
|
||||
temp_c int NOT NULL DEFAULT -1
|
||||
);
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_unlogged"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
\set ON_ERROR_STOP 1
|
||||
|
||||
ALTER TABLE PUBLIC."Hypertable_unlogged" SET LOGGED;
|
||||
SELECT * FROM create_hypertable('"public"."Hypertable_unlogged"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
|
||||
CREATE TEMP TABLE "Hypertable_temp" (
|
||||
time BIGINT NOT NULL,
|
||||
"Device_id" TEXT NOT NULL,
|
||||
temp_c int NOT NULL DEFAULT -1
|
||||
);
|
||||
|
||||
\set ON_ERROR_STOP 0
|
||||
SELECT * FROM create_hypertable('"Hypertable_temp"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
|
||||
|
||||
ALTER TABLE "Hypertable_1" SET UNLOGGED;
|
||||
\set ON_ERROR_STOP 1
|
||||
|
||||
ALTER TABLE "Hypertable_1" SET LOGGED;
|
||||
|
Loading…
x
Reference in New Issue
Block a user