Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug #134

Per recommendation from Steve Singer, UPDATE FUNCTIONS should try adding
TRUNCATE triggers, if possible (e.g. - on 8.4+).

--> Added version-specific functions that rummage thru sl_table and
    run functions to add + activate truncate triggers

   - NOOP for 8.3

   - active code for 8.4+

--> upgradeSchema() calls whichever truncate activation function is found
  • Loading branch information...
commit f1fb66ceec3d32039f83f293a362668d9d820746 1 parent 70765a3
Christopher Browne authored
View
2  src/backend/slony1_funcs.sql
@@ -5397,6 +5397,8 @@ begin
raise exception 'Upgrading to Slony-I 2.x requires running slony_upgrade_20';
end if;
+ perform @NAMESPACE@.add_truncate_triggers();
+
return p_old;
end;
$$ language plpgsql;
View
14 src/backend/slony1_funcs.v83.sql
@@ -53,9 +53,6 @@ end;$$ language plpgsql;
comment on function @NAMESPACE@.ShouldSlonyVacuumTable (name, name) is
'returns false if autovacuum handles vacuuming of the table, or if the table does not exist; returns true if Slony-I should manage it';
-
-
-
create or replace function @NAMESPACE@.TruncateOnlyTable ( name) returns void as
$$
begin
@@ -96,3 +93,14 @@ comment on function @NAMESPACE@.origin_truncate_trigger(i_fqname text) is
'disable deny access, enable log trigger on origin.
NOOP on PostgreSQL 8.3 because it does not support triggers ON TRUNCATE';
+
+create or replace function @NAMESPACE@.add_truncate_triggers () returns integer as $$
+begin
+ raise warning 'This node is running PostgreSQL 8.3 - cannot apply TRUNCATE triggers';
+ return 0;
+end
+$$ language plpgsql;
+
+comment on function @NAMESPACE@.add_truncate_triggers () is
+'Add ON TRUNCATE triggers to replicated tables. Not supported on PG 8.3, so a NOOP in this case.';
+
View
35 src/backend/slony1_funcs.v84.sql
@@ -103,3 +103,38 @@ end $$ language plpgsql;
comment on function @NAMESPACE@.origin_truncate_trigger(i_fqname text) is
'disable deny access, enable log trigger on origin.';
+
+create or replace function @NAMESPACE@.add_truncate_triggers () returns integer as $$
+begin
+
+ --- Add truncate triggers
+ begin
+ perform @NAMESPACE@.addtruncatetrigger(@NAMESPACE@.slon_quote_brute(tab_nspname) || '.' || @NAMESPACE@.slon_quote_brute(tab_relname), tab_id)
+ from @NAMESPACE@.sl_table
+ where 2 <> (select count(*) from information_schema.triggers where
+ event_object_schema = tab_nspname and trigger_name in ('_@CLUSTERNAME@_truncatedeny', '_@CLUSTERNAME@_truncatetrigger') and
+ event_object_table = tab_relname);
+
+ exception when unique_violation then
+ raise warning 'add_truncate_triggers() - uniqueness violation';
+ raise warning 'likely due to truncate triggers existing partially';
+ raise exception 'add_truncate_triggers() - failure - [%][%]', SQLSTATE, SQLERRM;
+ end;
+
+ -- Activate truncate triggers for replica
+ perform @NAMESPACE@.replica_truncate_trigger(@NAMESPACE@.slon_quote_brute(tab_nspname) || '.' || @NAMESPACE@.slon_quote_brute(tab_relname))
+ from @NAMESPACE@.sl_table
+ where tab_set not in (select set_id from @NAMESPACE@.sl_set where set_origin = @NAMESPACE@.getLocalNodeId('_@CLUSTERNAME@'));
+
+ -- Activate truncate triggers for origin
+ perform @NAMESPACE@.origin_truncate_trigger(@NAMESPACE@.slon_quote_brute(tab_nspname) || '.' || @NAMESPACE@.slon_quote_brute(tab_relname))
+ from @NAMESPACE@.sl_table
+ where tab_set in (select set_id from @NAMESPACE@.sl_set where set_origin = @NAMESPACE@.getLocalNodeId('_@CLUSTERNAME@'));
+
+ return 1;
+end
+$$ language plpgsql;
+
+comment on function @NAMESPACE@.add_truncate_triggers () is
+'Add ON TRUNCATE triggers to replicated tables.';
+
Please sign in to comment.
Something went wrong with that request. Please try again.