diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-02-04 00:26:10 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-02-04 00:26:10 -0500 |
commit | 411e2b0d59947b8fce39906b4722781895e31b1e (patch) | |
tree | ac3a2e5867d2edb3ce3a51f485d5a9d7aafff647 | |
parent | c27fda69c919d3fcde5f4dfef11747f1584ed123 (diff) | |
download | postgresql-411e2b0d59947b8fce39906b4722781895e31b1e.tar.gz |
In pg_dump, ensure that view triggers are processed after view rules.
If a view is split into CREATE TABLE + CREATE RULE to break a circular
dependency, then any triggers on the view must be dumped/reloaded after
the CREATE RULE; else the backend may reject the CREATE TRIGGER because
it's the wrong type of trigger for a plain table. This works all right
in plain dump/restore because of pg_dump's sorting heuristic that places
triggers after rules. However, when using parallel restore, the ordering
must be enforced by a dependency --- and we didn't have one.
Fixing this is a mere matter of adding an addObjectDependency() call,
except that we need to be able to find all the triggers belonging to the
view relation, and there was no easy way to do that. Add fields to
pg_dump's TableInfo struct to remember where the associated TriggerInfo
struct(s) are.
Per bug report from Dennis Kögel. The failure can be exhibited at least
as far back as 9.1, so back-patch to all supported branches.
-rw-r--r-- | src/bin/pg_dump/pg_dump.c | 3 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump.h | 2 | ||||
-rw-r--r-- | src/bin/pg_dump/pg_dump_sort.c | 4 |
3 files changed, 9 insertions, 0 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 23c520d5cb..41ca186df9 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -5905,6 +5905,9 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo)); + tbinfo->numTriggers = ntups; + tbinfo->triggers = tginfo; + for (j = 0; j < ntups; j++) { tginfo[j].dobj.objType = DO_TRIGGER; diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h index e563a8df4c..ef0ba259d8 100644 --- a/src/bin/pg_dump/pg_dump.h +++ b/src/bin/pg_dump/pg_dump.h @@ -289,6 +289,8 @@ typedef struct _tableInfo int numParents; /* number of (immediate) parent tables */ struct _tableInfo **parents; /* TableInfos of immediate parents */ struct _tableDataInfo *dataObj; /* TableDataInfo, if dumping its data */ + int numTriggers; /* number of triggers for table */ + struct _triggerInfo *triggers; /* array of TriggerInfo structs */ } TableInfo; typedef struct _attrDefInfo diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c index 6d970dd899..679cda12a7 100644 --- a/src/bin/pg_dump/pg_dump_sort.c +++ b/src/bin/pg_dump/pg_dump_sort.c @@ -878,6 +878,7 @@ repairViewRuleMultiLoop(DumpableObject *viewobj, { TableInfo *viewinfo = (TableInfo *) viewobj; RuleInfo *ruleinfo = (RuleInfo *) ruleobj; + int i; /* remove view's dependency on rule */ removeObjectDependency(viewobj, ruleobj->dumpId); @@ -895,6 +896,9 @@ repairViewRuleMultiLoop(DumpableObject *viewobj, addObjectDependency(ruleobj, viewobj->dumpId); /* now that rule is separate, it must be post-data */ addObjectDependency(ruleobj, postDataBoundId); + /* also, any triggers on the view must be dumped after the rule */ + for (i = 0; i < viewinfo->numTriggers; i++) + addObjectDependency(&(viewinfo->triggers[i].dobj), ruleobj->dumpId); } /* |