bdr: Don't create TRUNCATE triggers for DDL replication during pg_restore
authorCraig Ringer <[email protected]>
Sun, 27 Apr 2014 04:47:24 +0000 (12:47 +0800)
committerAndres Freund <[email protected]>
Thu, 3 Jul 2014 15:55:27 +0000 (17:55 +0200)
contrib/bdr/bdr--0.5.sql
contrib/bdr/bdr.c
contrib/bdr/scripts/bdr_initial_load

index 9e56d262ce2b385b694220bc6bf704eac3ff88e2..4df82521e2b2a35d9fdd267878e6be63c4ee8833 100644 (file)
@@ -189,6 +189,12 @@ BEGIN
     IF pg_replication_identifier_is_replaying() THEN
        RETURN;
     END IF;
+    IF current_setting('bdr.skip_ddl_replication')::boolean THEN
+        -- If we're doing a pg_restore from a remote BDR node's
+        -- state, we must not create truncate triggers etc because
+        -- they'll get copied over in the dump.
+        RETURN;
+    END IF;
 
     FOR r IN SELECT * FROM pg_event_trigger_get_creation_commands()
     LOOP
index 36b109514e15daa1fa33dc943cee1c14059e6b78..e45f554d3307e68e5c906db8125172a42248a608 100644 (file)
@@ -70,6 +70,7 @@ static char *connections = NULL;
 static char *bdr_synchronous_commit = NULL;
 int bdr_default_apply_delay;
 int bdr_max_workers;
+static bool bdr_skip_ddl_replication;
 
 /* TODO: Remove when bdr_apply_main moved into bdr_apply.c */
 extern BdrApplyWorker *bdr_apply_worker;
@@ -1444,6 +1445,15 @@ _PG_init(void)
                               0,
                               NULL, NULL, NULL);
 
+   DefineCustomBoolVariable("bdr.skip_ddl_replication",
+                            "Internal. Set during local restore during init_replica only",
+                            NULL,
+                            &bdr_skip_ddl_replication,
+                            false,
+                            PGC_BACKEND,
+                            0,
+                            NULL, NULL, NULL);
+
    /* if nothing is configured, we're done */
    if (connections == NULL)
    {
index b2b05d2610118fc0982ae3c1fedd5d20971c2129..ac4c5856adec266ec153981ff7942d93a62ef8f5 100644 (file)
@@ -65,7 +65,7 @@ if ! pg_dump -j $JOBS $SNAP -F d -f $TMPDIR "$SOURCE"; then
 fi
 
 echo "Restoring dump to local DB \"$TARGET\" with $JOBS concurrent workers from \"$TMPDIR\""
-if ! PGOPTIONS="-c bdr.permit_unsafe_ddl_commands=true" pg_restore --exit-on-error --single-transaction -j $JOBS -F d -d "$TARGET" $TMPDIR; then
+if ! PGOPTIONS="-c bdr.permit_unsafe_ddl_commands=true -c bdr.skip_ddl_replication=true" pg_restore --exit-on-error --single-transaction -j $JOBS -F d -d "$TARGET" $TMPDIR; then
     echo "pg_restore to "$TARGET" failed, aborting"
     exit 2
 fi