Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cd3413e

Browse files
committed
Disable event triggers in standalone mode.
Per discussion, this seems necessary to allow recovery from broken event triggers, or broken indexes on pg_event_trigger. Dimitri Fontaine
1 parent b19e425 commit cd3413e

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

doc/src/sgml/ref/create_event_trigger.sgml

+9-2
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,22 @@ CREATE EVENT TRIGGER <replaceable class="PARAMETER">name</replaceable>
108108
<title>Notes</title>
109109

110110
<para>
111-
To create a trigger on a event, the user must be superuser.
111+
Only superusers can create event triggers.
112+
</para>
113+
114+
<para>
115+
Event triggers are disabled in single-user mode (see <xref
116+
linkend="app-postgres">). If an erroneous event trigger disables the
117+
database so much that you can't even drop the trigger, restart in
118+
single-user mode and you'll be able to do that.
112119
</para>
113120
</refsect1>
114121

115122
<refsect1 id="sql-createeventtrigger-examples">
116123
<title>Examples</title>
117124

118125
<para>
119-
Forbid the execution of any <link linkend="ddl">ddl</link> command:
126+
Forbid the execution of any <link linkend="ddl">DDL</link> command:
120127

121128
<programlisting>
122129
CREATE OR REPLACE FUNCTION abort_any_command()

src/backend/commands/event_trigger.c

+19
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,25 @@ EventTriggerDDLCommandStart(Node *parsetree)
566566
const char *tag;
567567
EventTriggerData trigdata;
568568

569+
/*
570+
* Event Triggers are completely disabled in standalone mode. There are
571+
* (at least) two reasons for this:
572+
*
573+
* 1. A sufficiently broken event trigger might not only render the
574+
* database unusable, but prevent disabling itself to fix the situation.
575+
* In this scenario, restarting in standalone mode provides an escape
576+
* hatch.
577+
*
578+
* 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
579+
* therefore will malfunction if pg_event_trigger's indexes are damaged.
580+
* To allow recovery from a damaged index, we need some operating mode
581+
* wherein event triggers are disabled. (Or we could implement
582+
* heapscan-and-sort logic for that case, but having disaster recovery
583+
* scenarios depend on code that's otherwise untested isn't appetizing.)
584+
*/
585+
if (!IsUnderPostmaster)
586+
return;
587+
569588
/*
570589
* We want the list of command tags for which this procedure is actually
571590
* invoked to match up exactly with the list that CREATE EVENT TRIGGER

0 commit comments

Comments
 (0)