diff options
author | Jan Wieck <JanWieck@Yahoo.com> | 2007-03-19 23:38:32 +0000 |
---|---|---|
committer | Jan Wieck <JanWieck@Yahoo.com> | 2007-03-19 23:38:32 +0000 |
commit | 0fe16500d3ae68b8928a2b94dcab434e358480d5 (patch) | |
tree | f1d9726d5922f2d486d4217cd4b02c4efbb63e5f /src/include/commands/trigger.h | |
parent | e927f8f14ee4059e8f582453984d96cbf9490a13 (diff) | |
download | postgresql-0fe16500d3ae68b8928a2b94dcab434e358480d5.tar.gz postgresql-0fe16500d3ae68b8928a2b94dcab434e358480d5.zip |
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 'src/include/commands/trigger.h')
-rw-r--r-- | src/include/commands/trigger.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index ac9eb7296d1..8fcd0bb6aa7 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.61 2007/02/14 01:58:58 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.62 2007/03/19 23:38:31 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -78,6 +78,18 @@ typedef struct TriggerData #define TRIGGER_FIRED_AFTER(event) \ (!TRIGGER_FIRED_BEFORE (event)) +/* + * Definitions for the replication role based firing. + */ +#define SESSION_REPLICATION_ROLE_ORIGIN 0 +#define SESSION_REPLICATION_ROLE_REPLICA 1 +#define SESSION_REPLICATION_ROLE_LOCAL 2 +extern int SessionReplicationRole; + +#define TRIGGER_FIRES_ON_ORIGIN 'O' +#define TRIGGER_FIRES_ALWAYS 'A' +#define TRIGGER_FIRES_ON_REPLICA 'R' +#define TRIGGER_DISABLED 'D' extern Oid CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid); @@ -88,7 +100,7 @@ extern void RemoveTriggerById(Oid trigOid); extern void renametrig(Oid relid, const char *oldname, const char *newname); extern void EnableDisableTrigger(Relation rel, const char *tgname, - bool enable, bool skip_system); + char fires_when, bool skip_system); extern void RelationBuildTriggers(Relation relation); |