diff --git a/pg_ivm.c b/pg_ivm.c index 7b7cb25..32641dd 100644 --- a/pg_ivm.c +++ b/pg_ivm.c @@ -269,13 +269,19 @@ IVM_prevent_immv_change(PG_FUNCTION_ARGS) TriggerData *trigdata = (TriggerData *) fcinfo->context; Relation rel = trigdata->tg_relation; - if (!ImmvIncrementalMaintenanceIsEnabled()) - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("cannot change materialized view \"%s\"", - RelationGetRelationName(rel)))); + if (ImmvIncrementalMaintenanceIsEnabled()) + return PointerGetDatum(NULL); - return PointerGetDatum(NULL); + /* + * If we are maintaining an IMMV, this warning would have been emitted by + * the IVM_immediate_* triggers, so there is no need to emit it again. + */ + warnIfPgIvmNotPreloaded(); + + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("cannot change materialized view \"%s\"", + RelationGetRelationName(rel)))); } /* @@ -467,7 +473,7 @@ PgIvmFuncName(char *name) * * Check if pg_ivm is in the shared_preload_libraries parameter. */ -bool +static bool pgIvmIsInSharedPreloadLibraries() { return check_string_in_guc_list("pg_ivm", shared_preload_libraries_string, @@ -479,13 +485,33 @@ pgIvmIsInSharedPreloadLibraries() * * Check if pg_ivm is in the session_preload_libraries parameter. */ -bool +static bool pgIvmIsInSessionPreloadLibraries() { return check_string_in_guc_list("pg_ivm", session_preload_libraries_string, "session_preload_libraries"); } +/* + * warnIfPgIvmNotPreloaded + * + * Emit a warning if pg_ivm is not in shared_preload_libraries or + * session_preload_libraries. + */ +void +warnIfPgIvmNotPreloaded() +{ + if (!pgIvmIsInSharedPreloadLibraries() && + !pgIvmIsInSessionPreloadLibraries()) + ereport(WARNING, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("pg_ivm is not loaded in shared_preload_libraries or " + "session_preload_libraries"), + errhint("Add pg_ivm to session_preload_libraries and restart " + "the session. Or, add pg_ivm to " + "shared_preload_libraries and restart Postgres."))); +} + /* * check_string_in_guc_list * diff --git a/pg_ivm.h b/pg_ivm.h index 081d4f8..c6c8e0e 100644 --- a/pg_ivm.h +++ b/pg_ivm.h @@ -34,8 +34,7 @@ extern Oid PgIvmImmvRelationId(void); extern Oid PgIvmImmvPrimaryKeyIndexId(void); extern bool isImmv(Oid immv_oid); extern List *PgIvmFuncName(char *name); -extern bool pgIvmIsInSharedPreloadLibraries(void); -extern bool pgIvmIsInSessionPreloadLibraries(void); +extern void warnIfPgIvmNotPreloaded(void); /* createas.c */