*/
if (_canRestoreBlobs(AH) && AH->createdBlobXref)
{
+ /* NULL parameter means disable ALL user triggers */
+ _disableTriggers(AH, NULL, ropt);
+
te = AH->toc->next;
while (te != AH->toc) {
te = te->next;
}
+
+ /* NULL parameter means enable ALL user triggers */
+ _enableTriggers(AH, NULL, ropt);
}
/*
*/
if (ropt->superuser)
{
- /* If we're not allowing changes for ownership, then remember the user
- * so we can change it back here. Otherwise, let _reconnectAsOwner
- * do what it has to do.
- */
- if (ropt->noOwner)
- oldUser = strdup(ConnectedUser(AH));
- _reconnectAsUser(AH, "-", ropt->superuser);
+ if (!_restoringToDB(AH) || !ConnectedUserIsSuperuser(AH))
+ {
+ /* If we're not allowing changes for ownership, then remember the user
+ * so we can change it back here. Otherwise, let _reconnectAsOwner
+ * do what it has to do.
+ */
+ if (ropt->noOwner)
+ oldUser = strdup(ConnectedUser(AH));
+ _reconnectAsUser(AH, "-", ropt->superuser);
+ }
}
ahlog(AH, 1, "Disabling triggers\n");
* command when one is available.
*/
ahprintf(AH, "-- Disable triggers\n");
- ahprintf(AH, "UPDATE \"pg_class\" SET \"reltriggers\" = 0 WHERE \"relname\" !~ '^pg_';\n\n");
+
+ /*
+ * Just update the AFFECTED table, if known.
+ */
+
+ if (te && te->name && strlen(te->name) > 0)
+ ahprintf(AH, "UPDATE \"pg_class\" SET \"reltriggers\" = 0 WHERE \"relname\" ~* '%s';\n",
+ te->name);
+ else
+ ahprintf(AH, "UPDATE \"pg_class\" SET \"reltriggers\" = 0 WHERE \"relname\" !~ '^pg_';\n\n");
/*
* Restore the user connection from the start of this procedure
*/
if (ropt->superuser)
{
- /* If we're not allowing changes for ownership, then remember the user
- * so we can change it back here. Otherwise, let _reconnectAsOwner
- * do what it has to do
- */
- if (ropt->noOwner)
- oldUser = strdup(ConnectedUser(AH));
+ if (!_restoringToDB(AH) || !ConnectedUserIsSuperuser(AH))
+ {
+ /* If we're not allowing changes for ownership, then remember the user
+ * so we can change it back here. Otherwise, let _reconnectAsOwner
+ * do what it has to do
+ */
+ if (ropt->noOwner)
+ oldUser = strdup(ConnectedUser(AH));
- _reconnectAsUser(AH, "-", ropt->superuser);
+ _reconnectAsUser(AH, "-", ropt->superuser);
+ }
}
ahlog(AH, 1, "Enabling triggers\n");
ahprintf(AH, "-- Enable triggers\n");
ahprintf(AH, "BEGIN TRANSACTION;\n");
ahprintf(AH, "CREATE TEMP TABLE \"tr\" (\"tmp_relname\" name, \"tmp_reltriggers\" smallint);\n");
- ahprintf(AH, "INSERT INTO \"tr\" SELECT C.\"relname\", count(T.\"oid\") FROM \"pg_class\" C,"
- " \"pg_trigger\" T WHERE C.\"oid\" = T.\"tgrelid\" AND C.\"relname\" !~ '^pg_' "
- " GROUP BY 1;\n");
+
+ /*
+ * Just update the affected table, if known.
+ */
+ if (te && te->name && strlen(te->name) > 0)
+ ahprintf(AH, "INSERT INTO \"tr\" SELECT C.\"relname\", count(T.\"oid\") FROM \"pg_class\" C,"
+ " \"pg_trigger\" T WHERE C.\"oid\" = T.\"tgrelid\" AND C.\"relname\" ~* '%s' "
+ " GROUP BY 1;\n", te->name);
+ else
+ ahprintf(AH, "INSERT INTO \"tr\" SELECT C.\"relname\", count(T.\"oid\") FROM \"pg_class\" C,"
+ " \"pg_trigger\" T WHERE C.\"oid\" = T.\"tgrelid\" AND C.\"relname\" !~ '^pg_' "
+ " GROUP BY 1;\n");
+
ahprintf(AH, "UPDATE \"pg_class\" SET \"reltriggers\" = TMP.\"tmp_reltriggers\" "
"FROM \"tr\" TMP WHERE "
"\"pg_class\".\"relname\" = TMP.\"tmp_relname\";\n");
if (loOid == 0)
die_horribly(AH, "%s: unable to create BLOB\n", progname);
- ahlog(AH, 1, "Restoring BLOB oid %d as %d\n", oid, loOid);
+ ahlog(AH, 2, "Restoring BLOB oid %d as %d\n", oid, loOid);
InsertBlobXref(AH, oid, loOid);
ahlog(AH, 1, " - %s.%s\n", tablename, attr);
resetPQExpBuffer(tblQry);
- appendPQExpBuffer(tblQry, "Update \"%s\" Set \"%s\" = x.newOid From %s x "
- "Where x.oldOid = \"%s\".\"%s\";",
- tablename, attr, BLOB_XREF_TABLE, tablename, attr);
+ /*
+ * We should use coalesce here (rather than 'exists'), but it seems to
+ * be broken in 7.0.2 (weird optimizer strategy)
+ */
+ appendPQExpBuffer(tblQry, "UPDATE \"%s\" SET \"%s\" = ",tablename, attr);
+ appendPQExpBuffer(tblQry, " (SELECT x.newOid FROM \"%s\" x WHERE x.oldOid = \"%s\".\"%s\")",
+ BLOB_XREF_TABLE, tablename, attr);
+ appendPQExpBuffer(tblQry, " where exists"
+ "(select * from %s x where x.oldOid = \"%s\".\"%s\");",
+ BLOB_XREF_TABLE, tablename, attr);
- ahlog(AH, 10, " - sql = %s\n", tblQry->data);
+ ahlog(AH, 10, " - sql:\n%s\n", tblQry->data);
uRes = PQexec(AH->blobConnection, tblQry->data);
if (!uRes)
die_horribly(AH, "%s: could not update attr %s of table %s. Explanation from backend '%s'\n",
- progname, attr, tablename, PQerrorMessage(AH->connection));
+ progname, attr, tablename, PQerrorMessage(AH->blobConnection));
if ( PQresultStatus(uRes) != PGRES_COMMAND_OK )
- die_horribly(AH, "%s: error while updating attr %s of table %s. Explanation from backend '%s'\n",
- progname, attr, tablename, PQerrorMessage(AH->connection));
+ die_horribly(AH, "%s: error while updating attr %s of table %s (result = %d)."
+ " Explanation from backend '%s'\n",
+ progname, attr, tablename, PQresultStatus(uRes),
+ PQerrorMessage(AH->blobConnection));
PQclear(uRes);
}
ahlog(AH, 1, "Creating table for BLOBS xrefs\n");
+/*
appendPQExpBuffer(qry, "Create Temporary Table %s(oldOid oid, newOid oid);", BLOB_XREF_TABLE);
+*/
+ appendPQExpBuffer(qry, "Create Table %s(oldOid oid, newOid oid);", BLOB_XREF_TABLE);
_executeSqlCommand(AH, AH->blobConnection, qry, "can not create BLOB xref table '" BLOB_XREF_TABLE "'");