Block replica identity usage with hypertables

This commit is contained in:
Matvey Arye 2018-07-24 15:08:49 -04:00 committed by Matvey Arye
parent 657a12f6f2
commit 122f5f15a4
4 changed files with 40 additions and 0 deletions

View File

@ -830,6 +830,13 @@ table_is_logged(Oid table_relid)
return get_rel_persistence(table_relid) == RELPERSISTENCE_PERMANENT;
}
static bool
table_has_replica_identity(Relation rel)
{
return rel->rd_rel->relreplident != REPLICA_IDENTITY_DEFAULT;
}
bool
hypertable_has_tuples(Oid table_relid, LOCKMODE lockmode)
{
@ -1051,6 +1058,12 @@ hypertable_create(PG_FUNCTION_ARGS)
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.")));
if (table_has_replica_identity(rel))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("table \"%s\" has replica identity set", get_rel_name(table_relid)),
errdetail("Logical replication is not supported on hypertables.")));
/*
* Create the associated schema where chunks are stored, or, check
* permissions if it already exists

View File

@ -1575,6 +1575,10 @@ process_altertable_end_subcmd(Hypertable *ht, Node *parsetree, ObjectAddress *ob
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("logging cannot be turned off for hypertables")));
case AT_ReplicaIdentity:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("hypertables do not support logical replication")));
break;
case AT_SetRelOptions:
case AT_ResetRelOptions:

View File

@ -81,3 +81,15 @@ 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;
CREATE TABLE PUBLIC."Hypertable_1_replica_ident" (
time BIGINT NOT NULL,
"Device_id" TEXT NOT NULL,
temp_c int NOT NULL DEFAULT -1
);
ALTER TABLE "Hypertable_1_replica_ident" REPLICA IDENTITY FULL;
\set ON_ERROR_STOP 0
SELECT * FROM create_hypertable('"public"."Hypertable_1_replica_ident"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
ERROR: table "Hypertable_1_replica_ident" has replica identity set
ALTER TABLE "Hypertable_1" REPLICA IDENTITY FULL;
ERROR: hypertables do not support logical replication
\set ON_ERROR_STOP 1

View File

@ -75,3 +75,14 @@ ALTER TABLE "Hypertable_1" SET UNLOGGED;
\set ON_ERROR_STOP 1
ALTER TABLE "Hypertable_1" SET LOGGED;
CREATE TABLE PUBLIC."Hypertable_1_replica_ident" (
time BIGINT NOT NULL,
"Device_id" TEXT NOT NULL,
temp_c int NOT NULL DEFAULT -1
);
ALTER TABLE "Hypertable_1_replica_ident" REPLICA IDENTITY FULL;
\set ON_ERROR_STOP 0
SELECT * FROM create_hypertable('"public"."Hypertable_1_replica_ident"', 'time', chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
ALTER TABLE "Hypertable_1" REPLICA IDENTITY FULL;
\set ON_ERROR_STOP 1