mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Add GUC for temporarily disabling event triggers
In order to troubleshoot misbehaving or buggy event triggers, the documented advice is to enter single-user mode. In an attempt to reduce the number of situations where single-user mode is required (or even recommended) for non-extraordinary maintenance, this GUC allows to temporarily suspend event triggers. This was originally extracted from a larger patchset which aimed at supporting event triggers on login events. Reviewed-by: Ted Yu <yuzhihong@gmail.com> Reviewed-by: Mikhail Gribkov <youzhick@gmail.com> Reviewed-by: Justin Pryzby <pryzby@telsasoft.com> Reviewed-by: Michael Paquier <michael@paquier.xyz Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/9140106E-F9BF-4D85-8FC8-F2D3C094A6D9@yesql.se Discussion: https://postgr.es/m/0d46d29f-4558-3af9-9c85-7774e14a7709@postgrespro.ru
This commit is contained in:
@@ -72,6 +72,9 @@ typedef struct EventTriggerQueryState
|
||||
|
||||
static EventTriggerQueryState *currentEventTriggerState = NULL;
|
||||
|
||||
/* GUC parameter */
|
||||
bool event_triggers = true;
|
||||
|
||||
/* Support for dropped objects */
|
||||
typedef struct SQLDropObject
|
||||
{
|
||||
@@ -657,8 +660,11 @@ EventTriggerDDLCommandStart(Node *parsetree)
|
||||
* wherein event triggers are disabled. (Or we could implement
|
||||
* heapscan-and-sort logic for that case, but having disaster recovery
|
||||
* scenarios depend on code that's otherwise untested isn't appetizing.)
|
||||
*
|
||||
* Additionally, event triggers can be disabled with a superuser-only GUC
|
||||
* to make fixing database easier as per 1 above.
|
||||
*/
|
||||
if (!IsUnderPostmaster)
|
||||
if (!IsUnderPostmaster || !event_triggers)
|
||||
return;
|
||||
|
||||
runlist = EventTriggerCommonSetup(parsetree,
|
||||
@@ -692,9 +698,9 @@ EventTriggerDDLCommandEnd(Node *parsetree)
|
||||
|
||||
/*
|
||||
* See EventTriggerDDLCommandStart for a discussion about why event
|
||||
* triggers are disabled in single user mode.
|
||||
* triggers are disabled in single user mode or via GUC.
|
||||
*/
|
||||
if (!IsUnderPostmaster)
|
||||
if (!IsUnderPostmaster || !event_triggers)
|
||||
return;
|
||||
|
||||
/*
|
||||
@@ -740,9 +746,9 @@ EventTriggerSQLDrop(Node *parsetree)
|
||||
|
||||
/*
|
||||
* See EventTriggerDDLCommandStart for a discussion about why event
|
||||
* triggers are disabled in single user mode.
|
||||
* triggers are disabled in single user mode or via a GUC.
|
||||
*/
|
||||
if (!IsUnderPostmaster)
|
||||
if (!IsUnderPostmaster || !event_triggers)
|
||||
return;
|
||||
|
||||
/*
|
||||
@@ -811,9 +817,9 @@ EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
|
||||
|
||||
/*
|
||||
* See EventTriggerDDLCommandStart for a discussion about why event
|
||||
* triggers are disabled in single user mode.
|
||||
* triggers are disabled in single user mode or via a GUC.
|
||||
*/
|
||||
if (!IsUnderPostmaster)
|
||||
if (!IsUnderPostmaster || !event_triggers)
|
||||
return;
|
||||
|
||||
/*
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/storage.h"
|
||||
#include "commands/async.h"
|
||||
#include "commands/event_trigger.h"
|
||||
#include "commands/tablespace.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "commands/user.h"
|
||||
@@ -2000,6 +2001,16 @@ struct config_bool ConfigureNamesBool[] =
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
{
|
||||
{"event_triggers", PGC_SUSET, CLIENT_CONN_STATEMENT,
|
||||
gettext_noop("Enables event triggers."),
|
||||
gettext_noop("When enabled, event triggers will fire for all applicable statements."),
|
||||
},
|
||||
&event_triggers,
|
||||
true,
|
||||
NULL, NULL, NULL
|
||||
},
|
||||
|
||||
/* End-of-list marker */
|
||||
{
|
||||
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
|
||||
|
||||
@@ -706,6 +706,7 @@
|
||||
#xmloption = 'content'
|
||||
#gin_pending_list_limit = 4MB
|
||||
#createrole_self_grant = '' # set and/or inherit
|
||||
#event_triggers = on
|
||||
|
||||
# - Locale and Formatting -
|
||||
|
||||
|
||||
Reference in New Issue
Block a user