diff options
author | Jan Wieck | 2007-03-19 23:38:32 +0000 |
---|---|---|
committer | Jan Wieck | 2007-03-19 23:38:32 +0000 |
commit | 0fe16500d3ae68b8928a2b94dcab434e358480d5 (patch) | |
tree | f1d9726d5922f2d486d4217cd4b02c4efbb63e5f /doc/src | |
parent | e927f8f14ee4059e8f582453984d96cbf9490a13 (diff) |
Changes pg_trigger and extend pg_rewrite in order to allow triggers and
rules to be defined with different, per session controllable, behaviors
for replication purposes.
This will allow replication systems like Slony-I and, as has been stated
on pgsql-hackers, other products to control the firing mechanism of
triggers and rewrite rules without modifying the system catalog directly.
The firing mechanisms are controlled by a new superuser-only GUC
variable, session_replication_role, together with a change to
pg_trigger.tgenabled and a new column pg_rewrite.ev_enabled. Both
columns are a single char data type now (tgenabled was a bool before).
The possible values in these attributes are:
'O' - Trigger/Rule fires when session_replication_role is "origin"
(default) or "local". This is the default behavior.
'D' - Trigger/Rule is disabled and fires never
'A' - Trigger/Rule fires always regardless of the setting of
session_replication_role
'R' - Trigger/Rule fires when session_replication_role is "replica"
The GUC variable can only be changed as long as the system does not have
any cached query plans. This will prevent changing the session role and
accidentally executing stored procedures or functions that have plans
cached that expand to the wrong query set due to differences in the rule
firing semantics.
The SQL syntax for changing a triggers/rules firing semantics is
ALTER TABLE <tabname> <when> TRIGGER|RULE <name>;
<when> ::= ENABLE | ENABLE ALWAYS | ENABLE REPLICA | DISABLE
psql's \d command as well as pg_dump are extended in a backward
compatible fashion.
Jan
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/catalogs.sgml | 27 | ||||
-rw-r--r-- | doc/src/sgml/config.sgml | 19 | ||||
-rw-r--r-- | doc/src/sgml/ref/alter_table.sgml | 33 |
3 files changed, 72 insertions, 7 deletions
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 9a9f9b55bef..31db6521c5e 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.145 2007/02/14 01:58:55 tgl Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.146 2007/03/19 23:38:28 wieck Exp $ --> <!-- Documentation of the system catalogs, directed toward PostgreSQL developers --> @@ -3640,6 +3640,20 @@ </row> <row> + <entry><structfield>ev_enabled</structfield></entry> + <entry><type>char</type></entry> + <entry></entry> + <entry> + Controls in which <xref linkend="guc-session-replication-role"> modes + the rule fires. + <literal>O</> = rule fires in <quote>origin</> and <quote>local</> modes, + <literal>D</> = rule is disabled, + <literal>R</> = rule fires in <quote>replica</> mode, + <literal>A</> = rule fires always. + </entry> + </row> + + <row> <entry><structfield>is_instead</structfield></entry> <entry><type>bool</type></entry> <entry></entry> @@ -4178,9 +4192,16 @@ <row> <entry><structfield>tgenabled</structfield></entry> - <entry><type>bool</type></entry> + <entry><type>char</type></entry> <entry></entry> - <entry>True if trigger is enabled</entry> + <entry> + Controls in which <xref linkend="guc-session-replication-role"> modes + the trigger fires. + <literal>O</> = trigger fires in <quote>origin</> and <quote>local</> modes, + <literal>D</> = trigger is disabled, + <literal>R</> = trigger fires in <quote>replica</> mode, + <literal>A</> = trigger fires always. + </entry> </row> <row> diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 17504b3d5e8..1fe39db2af7 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.115 2007/03/06 02:06:12 momjian Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.116 2007/03/19 23:38:28 wieck Exp $ --> <chapter Id="runtime-config"> <title>Server Configuration</title> @@ -3523,6 +3523,23 @@ SELECT * FROM parent WHERE key = 2400; </listitem> </varlistentry> + <varlistentry id="guc-session-replication-role" xreflabel="session_replication_role"> + <term><varname>session_replication_role</varname> (<type>string</type>)</term> + <indexterm> + <primary><varname>session_replication_role</> configuration parameter</primary> + </indexterm> + <listitem> + <para> + Controls the trigger and rule firing for the current session. + See <xref linkend="sql-altertable"> for the different options to + enable or disable triggers and rules. Setting the variable requires + superuser privilege and can only be done before any query plans have + been cached. Possible values are <literal>origin</>, + <literal>replica</> and <literal>local</>. + </para> + </listitem> + </varlistentry> + <varlistentry id="guc-vacuum-freeze-min-age" xreflabel="vacuum_freeze_min_age"> <term><varname>vacuum_freeze_min_age</varname> (<type>integer</type>)</term> <indexterm> diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 6ff289b21a4..9b34c4fb993 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -1,5 +1,5 @@ <!-- -$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.94 2007/02/01 00:28:18 momjian Exp $ +$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.95 2007/03/19 23:38:29 wieck Exp $ PostgreSQL documentation --> @@ -43,6 +43,12 @@ where <replaceable class="PARAMETER">action</replaceable> is one of: DROP CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable> [ RESTRICT | CASCADE ] DISABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ] ENABLE TRIGGER [ <replaceable class="PARAMETER">trigger_name</replaceable> | ALL | USER ] + ENABLE REPLICA TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> + ENABLE ALWAYS TRIGGER <replaceable class="PARAMETER">trigger_name</replaceable> + DISABLE RULE <replaceable class="PARAMETER">rewrite_rule_name</replaceable> + ENABLE RULE <replaceable class="PARAMETER">rewrite_rule_name</replaceable> + ENABLE REPLICA RULE <replaceable class="PARAMETER">rewrite_rule_name</replaceable> + ENABLE ALWAYS RULE <replaceable class="PARAMETER">rewrite_rule_name</replaceable> CLUSTER ON <replaceable class="PARAMETER">index_name</replaceable> SET WITHOUT CLUSTER SET WITHOUT OIDS @@ -193,10 +199,10 @@ where <replaceable class="PARAMETER">action</replaceable> is one of: </varlistentry> <varlistentry> - <term><literal>DISABLE</literal>/<literal>ENABLE TRIGGER</literal></term> + <term><literal>DISABLE</literal>/<literal>ENABLE [ REPLICA | ALWAYS ] TRIGGER</literal></term> <listitem> <para> - These forms disable or enable trigger(s) belonging to the table. + These forms configure the firing of trigger(s) belonging to the table. A disabled trigger is still known to the system, but is not executed when its triggering event occurs. For a deferred trigger, the enable status is checked when the event occurs, not when the trigger function @@ -207,6 +213,27 @@ where <replaceable class="PARAMETER">action</replaceable> is one of: requires superuser privileges; it should be done with caution since of course the integrity of the constraint cannot be guaranteed if the triggers are not executed. + The trigger firing mechanism is also affected by the configuration + variable <xref linkend="guc-session-replication-role">. Simply ENABLEd + triggers will fire when the replication role is <quote>origin</> + (the default) or <quote>local</>. Triggers configured ENABLE REPLICA + will only fire if the session is in <quote>replica</> mode and triggers + configured ENABLE ALWAYS will fire regardless of the current replication + mode. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><literal>DISABLE</literal>/<literal>ENABLE [ REPLICA | ALWAYS ] RULE</literal></term> + <listitem> + <para> + These forms configure the firing of rewrite rules belonging to the table. + A disabled rule is still known to the system, but is not applied + during query rewriting. The semantics are as for disabled/enabled + triggers. This configuration is ignored for ON SELECT rules, which + are always applied in order to keep views working even if the current + session is in a non-default replication role. </para> </listitem> </varlistentry> |