]> granicus.if.org Git - postgresql/commitdiff
Initialize tableoid field correctly when dumping foreign data wrappers and
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 23 Sep 2010 11:49:00 +0000 (14:49 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Thu, 23 Sep 2010 11:58:35 +0000 (14:58 +0300)
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

index fdf48fe101889f6d2522261cf9ed1d92eb5d20ab..06c1f3ae605103593f2af3d9a8d858b098658914 100644 (file)
@@ -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));