From 7e8c25c66e9837d5dafeb2b3a0786611226af269 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 23 Sep 2010 14:49:00 +0300 Subject: [PATCH] Initialize tableoid field correctly when dumping foreign data wrappers and servers. AFAICT it's harmless at the moment because nothing can depend on either, but as soon as we introduce an object type with such dependencies, tableoid needs to be set or pg_dump will fail to interpret the dependencies correctly. In theory, I guess the uninitialized garbage in tableoid could cause the object to be mistaken for some other object with same OID as well. --- src/bin/pg_dump/pg_dump.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index fdf48fe101..06c1f3ae60 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -5851,6 +5851,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) int i; PQExpBuffer query = createPQExpBuffer(); FdwInfo *fdwinfo; + int i_tableoid; int i_oid; int i_fdwname; int i_rolname; @@ -5868,7 +5869,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) /* Make sure we are in proper schema */ selectSourceSchema("pg_catalog"); - appendPQExpBuffer(query, "SELECT oid, fdwname, " + appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, " "(%s fdwowner) AS rolname, fdwvalidator::pg_catalog.regproc, fdwacl," "array_to_string(ARRAY(" " SELECT option_name || ' ' || quote_literal(option_value) " @@ -5884,6 +5885,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) fdwinfo = (FdwInfo *) malloc(ntups * sizeof(FdwInfo)); + i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_fdwname = PQfnumber(res, "fdwname"); i_rolname = PQfnumber(res, "rolname"); @@ -5894,6 +5896,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) for (i = 0; i < ntups; i++) { fdwinfo[i].dobj.objType = DO_FDW; + fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&fdwinfo[i].dobj); fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname)); @@ -5930,6 +5933,7 @@ getForeignServers(int *numForeignServers) int i; PQExpBuffer query = createPQExpBuffer(); ForeignServerInfo *srvinfo; + int i_tableoid; int i_oid; int i_srvname; int i_rolname; @@ -5949,7 +5953,7 @@ getForeignServers(int *numForeignServers) /* Make sure we are in proper schema */ selectSourceSchema("pg_catalog"); - appendPQExpBuffer(query, "SELECT oid, srvname, " + appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, " "(%s srvowner) AS rolname, " "srvfdw, srvtype, srvversion, srvacl," "array_to_string(ARRAY(" @@ -5966,6 +5970,7 @@ getForeignServers(int *numForeignServers) srvinfo = (ForeignServerInfo *) malloc(ntups * sizeof(ForeignServerInfo)); + i_tableoid = PQfnumber(res, "tableoid"); i_oid = PQfnumber(res, "oid"); i_srvname = PQfnumber(res, "srvname"); i_rolname = PQfnumber(res, "rolname"); @@ -5978,6 +5983,7 @@ getForeignServers(int *numForeignServers) for (i = 0; i < ntups; i++) { srvinfo[i].dobj.objType = DO_FOREIGN_SERVER; + srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid)); srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); AssignDumpId(&srvinfo[i].dobj); srvinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_srvname)); -- 2.40.0