- Only disable triggers for the table being loaded
- disable triggers prior to BLOB load - better query for loading blob xrefs - Fixes to error handling code
This commit is contained in:
parent
129f1a31aa
commit
c2e302071f
@ -252,6 +252,9 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
|
||||
*/
|
||||
if (_canRestoreBlobs(AH) && AH->createdBlobXref)
|
||||
{
|
||||
/* NULL parameter means disable ALL user triggers */
|
||||
_disableTriggers(AH, NULL, ropt);
|
||||
|
||||
te = AH->toc->next;
|
||||
while (te != AH->toc) {
|
||||
|
||||
@ -275,6 +278,9 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
|
||||
|
||||
te = te->next;
|
||||
}
|
||||
|
||||
/* NULL parameter means enable ALL user triggers */
|
||||
_enableTriggers(AH, NULL, ropt);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -334,6 +340,8 @@ static void _disableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ro
|
||||
* who can update pg_class...
|
||||
*/
|
||||
if (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
|
||||
@ -343,6 +351,7 @@ static void _disableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ro
|
||||
oldUser = strdup(ConnectedUser(AH));
|
||||
_reconnectAsUser(AH, "-", ropt->superuser);
|
||||
}
|
||||
}
|
||||
|
||||
ahlog(AH, 1, "Disabling triggers\n");
|
||||
|
||||
@ -351,6 +360,15 @@ static void _disableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ro
|
||||
* command when one is available.
|
||||
*/
|
||||
ahprintf(AH, "-- Disable triggers\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");
|
||||
|
||||
/*
|
||||
@ -377,6 +395,8 @@ static void _enableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
|
||||
* who can update pg_class...
|
||||
*/
|
||||
if (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
|
||||
@ -387,6 +407,7 @@ static void _enableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
|
||||
|
||||
_reconnectAsUser(AH, "-", ropt->superuser);
|
||||
}
|
||||
}
|
||||
|
||||
ahlog(AH, 1, "Enabling triggers\n");
|
||||
|
||||
@ -397,9 +418,19 @@ static void _enableTriggers(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
|
||||
ahprintf(AH, "-- Enable triggers\n");
|
||||
ahprintf(AH, "BEGIN TRANSACTION;\n");
|
||||
ahprintf(AH, "CREATE TEMP TABLE \"tr\" (\"tmp_relname\" name, \"tmp_reltriggers\" smallint);\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");
|
||||
@ -580,7 +611,7 @@ void StartRestoreBlob(ArchiveHandle* AH, int oid)
|
||||
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);
|
||||
|
||||
|
@ -59,7 +59,7 @@ typedef z_stream *z_streamp;
|
||||
|
||||
#define K_VERS_MAJOR 1
|
||||
#define K_VERS_MINOR 4
|
||||
#define K_VERS_REV 8
|
||||
#define K_VERS_REV 10
|
||||
|
||||
/* Data block types */
|
||||
#define BLK_DATA 1
|
||||
|
@ -593,21 +593,30 @@ void FixupBlobRefs(ArchiveHandle *AH, char *tablename)
|
||||
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);
|
||||
}
|
||||
@ -631,7 +640,10 @@ void CreateBlobXrefTable(ArchiveHandle* AH)
|
||||
|
||||
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 "'");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user