Update pg_dump to use SET DEFAULT_TABLESPACE instead of explicit
authorTom Lane
Sat, 6 Nov 2004 19:36:02 +0000 (19:36 +0000)
committerTom Lane
Sat, 6 Nov 2004 19:36:02 +0000 (19:36 +0000)
tablespace clauses; this should improve compatibility of dump files.
Philip Warner, some rework by Tom Lane.

src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dump.c

index 293985508f1d314132e47c315c82d7ff68942716..d606024f451e34956ae485d7395d1331497222af 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.33 2004/08/29 05:06:53 momjian Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.34 2004/11/06 19:36:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -54,8 +54,10 @@ typedef enum _archiveFormat
 typedef struct _Archive
 {
    int         verbose;
-   int         remoteVersion;
-   int         minRemoteVersion;
+   char       *remoteVersionStr;   /* server's version string */
+   int         remoteVersion;      /* same in numeric form */
+
+   int         minRemoteVersion;   /* allowable range */
    int         maxRemoteVersion;
 
    /* error handling */
@@ -139,7 +141,8 @@ PGconn *ConnectDatabase(Archive *AH,
 extern void ArchiveEntry(Archive *AHX,
             CatalogId catalogId, DumpId dumpId,
             const char *tag,
-            const char *namespace, const char *owner, bool withOids,
+            const char *namespace, const char *tablespace,
+            const char *owner, bool withOids,
             const char *desc, const char *defn,
             const char *dropStmt, const char *copyStmt,
             const DumpId *deps, int nDeps,
index 17c50c71c56466333c8273c6fa227ab7bdd44ba7..002e329fea45ec550c3a586721c9c7eec5fc5528 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.99 2004/10/22 16:04:35 petere Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.100 2004/11/06 19:36:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -60,6 +60,7 @@ static void _reconnectToDB(ArchiveHandle *AH, const char *dbname);
 static void _becomeUser(ArchiveHandle *AH, const char *user);
 static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
 static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName);
+static void _selectTablespace(ArchiveHandle *AH, const char *tablespace);
 
 static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool acl_pass);
 static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
@@ -602,7 +603,9 @@ void
 ArchiveEntry(Archive *AHX,
             CatalogId catalogId, DumpId dumpId,
             const char *tag,
-            const char *namespace, const char *owner, bool withOids,
+            const char *namespace,
+            const char *tablespace, 
+            const char *owner, bool withOids,
             const char *desc, const char *defn,
             const char *dropStmt, const char *copyStmt,
             const DumpId *deps, int nDeps,
@@ -629,6 +632,7 @@ ArchiveEntry(Archive *AHX,
 
    newToc->tag = strdup(tag);
    newToc->namespace = namespace ? strdup(namespace) : NULL;
+   newToc->tablespace = tablespace ? strdup(tablespace) : NULL;
    newToc->owner = strdup(owner);
    newToc->withOids = withOids;
    newToc->desc = strdup(desc);
@@ -693,6 +697,12 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
    ahprintf(AH, ";     Format: %s\n", fmtName);
    ahprintf(AH, ";     Integer: %d bytes\n", (int) AH->intSize);
    ahprintf(AH, ";     Offset: %d bytes\n", (int) AH->offSize);
+   if (AH->archiveRemoteVersion)
+       ahprintf(AH, ";     Dumped from database version: %s\n",
+                AH->archiveRemoteVersion);
+   if (AH->archiveDumpVersion)
+       ahprintf(AH, ";     Dumped by pg_dump version: %s\n",
+                AH->archiveDumpVersion);
 
    ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n");
 
@@ -1822,6 +1832,7 @@ WriteToc(ArchiveHandle *AH)
        WriteStr(AH, te->dropStmt);
        WriteStr(AH, te->copyStmt);
        WriteStr(AH, te->namespace);
+       WriteStr(AH, te->tablespace);
        WriteStr(AH, te->owner);
        WriteStr(AH, te->withOids ? "true" : "false");
 
@@ -1891,6 +1902,9 @@ ReadToc(ArchiveHandle *AH)
        if (AH->version >= K_VERS_1_6)
            te->namespace = ReadStr(AH);
 
+       if (AH->version >= K_VERS_1_10)
+           te->tablespace = ReadStr(AH);
+
        te->owner = ReadStr(AH);
        if (AH->version >= K_VERS_1_9)
        {
@@ -2293,6 +2307,61 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
    destroyPQExpBuffer(qry);
 }
 
+/*
+ * Issue the commands to select the specified tablespace as the current one
+ * in the target database.
+ */
+static void
+_selectTablespace(ArchiveHandle *AH, const char *tablespace)
+{
+   PQExpBuffer qry;
+   const char  *want, *have;
+
+   have = AH->currTablespace;
+   want = tablespace;
+
+   /* no need to do anything for non-tablespace object */
+   if (!want)
+       return;
+
+   if (have && strcmp(want, have) == 0)
+       return;                 /* no need to do anything */
+
+   qry = createPQExpBuffer();
+
+   if (strcmp(want, "") == 0)
+   {
+       /* We want the tablespace to be the database's default */
+       appendPQExpBuffer(qry, "SET default_tablespace = ''");
+   }
+   else
+   {
+       /* We want an explicit tablespace */
+       appendPQExpBuffer(qry, "SET default_tablespace = %s", fmtId(want));
+   }
+
+   if (RestoringToDB(AH))
+   {
+       PGresult   *res;
+
+       res = PQexec(AH->connection, qry->data);
+
+       if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
+           warn_or_die_horribly(AH, modulename, 
+                                "could not set default_tablespace to %s: %s",
+                                fmtId(want), PQerrorMessage(AH->connection));
+
+       PQclear(res);
+   }
+   else
+       ahprintf(AH, "%s;\n\n", qry->data);
+
+   if (AH->currTablespace)
+       free(AH->currTablespace);
+   AH->currTablespace = strdup(want);
+
+   destroyPQExpBuffer(qry);
+}
 
 /**
  * Parses the dropStmt part of a TOC entry and returns
@@ -2378,9 +2447,10 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
        strcmp(te->desc, "SCHEMA") == 0 && strcmp(te->tag, "public") == 0)
        return;
 
-   /* Select owner and schema as necessary */
+   /* Select owner, schema, and tablespace as necessary */
    _becomeOwner(AH, te);
    _selectOutputSchema(AH, te->namespace);
+   _selectTablespace(AH, te->tablespace);
 
    /* Set up OID mode too */
    if (strcmp(te->desc, "TABLE") == 0)
@@ -2411,10 +2481,14 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
                ahprintf(AH, "\n");
            }
        }
-       ahprintf(AH, "-- %sName: %s; Type: %s; Schema: %s; Owner: %s\n",
+       ahprintf(AH, "-- %sName: %s; Type: %s; Schema: %s; Owner: %s",
                 pfx, te->tag, te->desc,
                 te->namespace ? te->namespace : "-",
                 te->owner);
+       if (te->tablespace) 
+           ahprintf(AH, "; Tablespace: %s", te->tablespace);
+       ahprintf(AH, "\n");
+
        if (AH->PrintExtraTocPtr != NULL)
            (*AH->PrintExtraTocPtr) (AH, te);
        ahprintf(AH, "--\n\n");
@@ -2509,6 +2583,8 @@ WriteHead(ArchiveHandle *AH)
    WriteInt(AH, crtm.tm_year);
    WriteInt(AH, crtm.tm_isdst);
    WriteStr(AH, PQdb(AH->connection));
+   WriteStr(AH, AH->public.remoteVersionStr);
+   WriteStr(AH, PG_VERSION);
 }
 
 void
@@ -2595,6 +2671,12 @@ ReadHead(ArchiveHandle *AH)
            write_msg(modulename, "WARNING: invalid creation date in header\n");
    }
 
+   if (AH->version >= K_VERS_1_10)
+   {
+       AH->archiveRemoteVersion = ReadStr(AH);
+       AH->archiveDumpVersion = ReadStr(AH);
+   }
+
 }
 
 
index c44a0ad1bf8874f4c136714830fa98afbe8eba58..dd92bc8d390aa01240bd53f7619d7f4fb0ab3df0 100644 (file)
@@ -17,7 +17,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.61 2004/08/29 05:06:53 momjian Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.62 2004/11/06 19:36:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
 #endif
 
 #define K_VERS_MAJOR 1
-#define K_VERS_MINOR 9
+#define K_VERS_MINOR 10
 #define K_VERS_REV 0
 
 /* Data block types */
@@ -84,8 +84,9 @@ typedef z_stream *z_streamp;
                                                                 * dependencies */
 #define K_VERS_1_9 (( (1 * 256 + 9) * 256 + 0) * 256 + 0)      /* add default_with_oids
                                                                 * tracking */
+#define K_VERS_1_10 (( (1 * 256 + 10) * 256 + 0) * 256 + 0)        /* add tablespace */
 
-#define K_VERS_MAX (( (1 * 256 + 9) * 256 + 255) * 256 + 0)
+#define K_VERS_MAX (( (1 * 256 + 10) * 256 + 255) * 256 + 0)
 
 /* No of BLOBs to restore in 1 TX */
 #define BLOB_BATCH_SIZE 100
@@ -171,6 +172,11 @@ typedef struct _archiveHandle
    char        vrev;
    int         version;        /* Conveniently formatted version */
 
+   char       *archiveRemoteVersion;   /* When reading an archive,
+                                        * the version of the dumped DB */
+   char       *archiveDumpVersion;     /* When reading an archive,
+                                        * the version of the dumper */
+
    int         debugLevel;     /* Used for logging (currently only by
                                 * --verbose) */
    size_t      intSize;        /* Size of an integer in the archive */
@@ -260,6 +266,7 @@ typedef struct _archiveHandle
    /* these vars track state to avoid sending redundant SET commands */
    char       *currUser;       /* current username */
    char       *currSchema;     /* current schema */
+   char       *currTablespace; /* current tablespace */
    bool        currWithOids;   /* current default_with_oids setting */
 
    void       *lo_buf;
@@ -283,6 +290,8 @@ typedef struct _tocEntry
                                 * (used in restore) */
    char       *tag;            /* index tag */
    char       *namespace;      /* null or empty string if not in a schema */
+   char       *tablespace;     /* null if not in a tablespace; empty string
+                                * means use database default */
    char       *owner;
    bool        withOids;       /* Used only by "TABLE" tags */
    char       *desc;
index 989fdf8287f2a910da297520c88078ea2b70a275..3a79f478332fd2c8cfd2ae6d1566c6892065b702 100644 (file)
@@ -5,7 +5,7 @@
  * Implements the basic DB functions used by the archiver.
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.60 2004/10/16 03:10:15 momjian Exp $
+ *   $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.61 2004/11/06 19:36:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -69,6 +69,7 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
 
    remoteversion = _parse_version(AH, remoteversion_str);
 
+   AH->public.remoteVersionStr = strdup(remoteversion_str);
    AH->public.remoteVersion = remoteversion;
 
    if (myversion != remoteversion
index 45510a98794817087379e31303a99a3ee95b31a5..b4739aeddc70ce25cf24062dae1af82ddba0b762 100644 (file)
@@ -12,7 +12,7 @@
  * by PostgreSQL
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.391 2004/11/05 19:16:19 tgl Exp $
+ *   $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.392 2004/11/06 19:36:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1101,6 +1101,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
    ArchiveEntry(fout, tdinfo->dobj.catId, tdinfo->dobj.dumpId,
                 tbinfo->dobj.name,
                 tbinfo->dobj.namespace->dobj.name,
+                NULL,
                 tbinfo->usename, false,
                 "TABLE DATA", "", "", copyStmt,
                 tdinfo->dobj.dependencies, tdinfo->dobj.nDeps,
@@ -1271,6 +1272,7 @@ dumpDatabase(Archive *AH)
                 dbDumpId,      /* dump ID */
                 datname,       /* Name */
                 NULL,          /* Namespace */
+                NULL,          /* Tablespace */
                 dba,           /* Owner */
                 false,         /* with oids */
                 "DATABASE",    /* Desc */
@@ -1316,7 +1318,7 @@ dumpTimestamp(Archive *AH, char *msg)
        appendPQExpBuffer(qry, "\n");
 
        ArchiveEntry(AH, nilCatalogId, createDumpId(),
-                    "DUMP TIMESTAMP", NULL, "",
+                    "DUMP TIMESTAMP", NULL, NULL, "",
                     false, "DUMP TIMESTAMP", qry->data, "", NULL,
                     NULL, 0,
                     NULL, NULL);
@@ -1356,7 +1358,7 @@ dumpEncoding(Archive *AH)
    appendPQExpBuffer(qry, ";\n");
 
    ArchiveEntry(AH, nilCatalogId, createDumpId(),
-                "ENCODING", NULL, "",
+                "ENCODING", NULL, NULL, "",
                 false, "ENCODING", qry->data, "", NULL,
                 NULL, 0,
                 NULL, NULL);
@@ -4039,7 +4041,7 @@ dumpComment(Archive *fout, const char *target,
        appendPQExpBuffer(query, ";\n");
 
        ArchiveEntry(fout, nilCatalogId, createDumpId(),
-                    target, namespace, owner, false,
+                    target, namespace, NULL, owner, false,
                     "COMMENT", query->data, "", NULL,
                     &(dumpId), 1,
                     NULL, NULL);
@@ -4098,7 +4100,9 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
 
            ArchiveEntry(fout, nilCatalogId, createDumpId(),
                         target->data,
-                     tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
+                        tbinfo->dobj.namespace->dobj.name,
+                        NULL,
+                        tbinfo->usename,
                         false, "COMMENT", query->data, "", NULL,
                         &(tbinfo->dobj.dumpId), 1,
                         NULL, NULL);
@@ -4118,7 +4122,9 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
 
            ArchiveEntry(fout, nilCatalogId, createDumpId(),
                         target->data,
-                     tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
+                        tbinfo->dobj.namespace->dobj.name,
+                        NULL,
+                        tbinfo->usename,
                         false, "COMMENT", query->data, "", NULL,
                         &(tbinfo->dobj.dumpId), 1,
                         NULL, NULL);
@@ -4367,7 +4373,7 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj)
            break;
        case DO_BLOBS:
            ArchiveEntry(fout, dobj->catId, dobj->dumpId,
-                        dobj->name, NULL, "",
+                        dobj->name, NULL, NULL, "",
                         false, "BLOBS", "", "", NULL,
                         NULL, 0,
                         dumpBlobs, NULL);
@@ -4414,7 +4420,8 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
 
    ArchiveEntry(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId,
                 nspinfo->dobj.name,
-                NULL, strcmp(nspinfo->dobj.name, "public") == 0 ? nspinfo->usename : "",
+                NULL, NULL, 
+                strcmp(nspinfo->dobj.name, "public") == 0 ? nspinfo->usename : "",
                 false, "SCHEMA", q->data, delq->data, NULL,
                 nspinfo->dobj.dependencies, nspinfo->dobj.nDeps,
                 NULL, NULL);
@@ -4705,6 +4712,7 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
    ArchiveEntry(fout, tinfo->dobj.catId, tinfo->dobj.dumpId,
                 tinfo->dobj.name,
                 tinfo->dobj.namespace->dobj.name,
+                NULL,
                 tinfo->usename, false,
                 "TYPE", q->data, delq->data, NULL,
                 tinfo->dobj.dependencies, tinfo->dobj.nDeps,
@@ -4811,6 +4819,7 @@ dumpDomain(Archive *fout, TypeInfo *tinfo)
    ArchiveEntry(fout, tinfo->dobj.catId, tinfo->dobj.dumpId,
                 tinfo->dobj.name,
                 tinfo->dobj.namespace->dobj.name,
+                NULL,
                 tinfo->usename, false,
                 "DOMAIN", q->data, delq->data, NULL,
                 tinfo->dobj.dependencies, tinfo->dobj.nDeps,
@@ -4904,6 +4913,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tinfo)
    ArchiveEntry(fout, tinfo->dobj.catId, tinfo->dobj.dumpId,
                 tinfo->dobj.name,
                 tinfo->dobj.namespace->dobj.name,
+                NULL,
                 tinfo->usename, false,
                 "TYPE", q->data, delq->data, NULL,
                 tinfo->dobj.dependencies, tinfo->dobj.nDeps,
@@ -4995,7 +5005,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
 
    ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
                 plang->dobj.name,
-                funcInfo->dobj.namespace->dobj.name, "",
+                funcInfo->dobj.namespace->dobj.name, NULL, "",
                 false, "PROCEDURAL LANGUAGE",
                 defqry->data, delqry->data, NULL,
                 plang->dobj.dependencies, plang->dobj.nDeps,
@@ -5269,6 +5279,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
    ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId,
                 funcsig_tag,
                 finfo->dobj.namespace->dobj.name,
+                NULL,
                 finfo->usename, false,
                 "FUNCTION", q->data, delqry->data, NULL,
                 finfo->dobj.dependencies, finfo->dobj.nDeps,
@@ -5408,7 +5419,7 @@ dumpCast(Archive *fout, CastInfo *cast)
 
    ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
                 castsig->data,
-                "pg_catalog", "",
+                "pg_catalog", NULL, "",
                 false, "CAST", defqry->data, delqry->data, NULL,
                 cast->dobj.dependencies, cast->dobj.nDeps,
                 NULL, NULL);
@@ -5661,7 +5672,9 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
 
    ArchiveEntry(fout, oprinfo->dobj.catId, oprinfo->dobj.dumpId,
                 oprinfo->dobj.name,
-                oprinfo->dobj.namespace->dobj.name, oprinfo->usename,
+                oprinfo->dobj.namespace->dobj.name, 
+                NULL,
+                oprinfo->usename,
                 false, "OPERATOR", q->data, delq->data, NULL,
                 oprinfo->dobj.dependencies, oprinfo->dobj.nDeps,
                 NULL, NULL);
@@ -5968,7 +5981,9 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
 
    ArchiveEntry(fout, opcinfo->dobj.catId, opcinfo->dobj.dumpId,
                 opcinfo->dobj.name,
-                opcinfo->dobj.namespace->dobj.name, opcinfo->usename,
+                opcinfo->dobj.namespace->dobj.name, 
+                NULL,
+                opcinfo->usename,
                 false, "OPERATOR CLASS", q->data, delq->data, NULL,
                 opcinfo->dobj.dependencies, opcinfo->dobj.nDeps,
                 NULL, NULL);
@@ -6078,7 +6093,9 @@ dumpConversion(Archive *fout, ConvInfo *convinfo)
 
    ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
                 convinfo->dobj.name,
-                convinfo->dobj.namespace->dobj.name, convinfo->usename,
+                convinfo->dobj.namespace->dobj.name, 
+                NULL, 
+                convinfo->usename,
                 false, "CONVERSION", q->data, delq->data, NULL,
                 convinfo->dobj.dependencies, convinfo->dobj.nDeps,
                 NULL, NULL);
@@ -6313,9 +6330,11 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
 
    ArchiveEntry(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
                 aggsig_tag,
-       agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.usename,
+                agginfo->aggfn.dobj.namespace->dobj.name,
+                NULL,
+                agginfo->aggfn.usename,
                 false, "AGGREGATE", q->data, delq->data, NULL,
-            agginfo->aggfn.dobj.dependencies, agginfo->aggfn.dobj.nDeps,
+                agginfo->aggfn.dobj.dependencies, agginfo->aggfn.dobj.nDeps,
                 NULL, NULL);
 
    /* Dump Aggregate Comments */
@@ -6392,6 +6411,7 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId,
    if (sql->len > 0)
        ArchiveEntry(fout, nilCatalogId, createDumpId(),
                     tag, nspname,
+                    NULL, 
                     owner ? owner : "",
                     false, "ACL", sql->data, "", NULL,
                     &(objDumpId), 1,
@@ -6629,11 +6649,6 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
            appendPQExpBuffer(q, ")");
        }
 
-       /* Output tablespace clause if not database's default */
-       if (strlen(tbinfo->reltablespace) != 0)
-           appendPQExpBuffer(q, " TABLESPACE %s",
-                             fmtId(tbinfo->reltablespace));
-
        appendPQExpBuffer(q, ";\n");
 
        /* Loop dumping statistics and storage statements */
@@ -6699,8 +6714,10 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 
    ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
                 tbinfo->dobj.name,
-                tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
-          (strcmp(reltypename, "TABLE") == 0) ? tbinfo->hasoids : false,
+                tbinfo->dobj.namespace->dobj.name,
+                (tbinfo->relkind == RELKIND_VIEW) ? NULL : tbinfo->reltablespace,
+                tbinfo->usename,
+                (strcmp(reltypename, "TABLE") == 0) ? tbinfo->hasoids : false,
                 reltypename, q->data, delq->data, NULL,
                 tbinfo->dobj.dependencies, tbinfo->dobj.nDeps,
                 NULL, NULL);
@@ -6754,7 +6771,9 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo)
 
    ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
                 tbinfo->attnames[adnum - 1],
-                tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
+                tbinfo->dobj.namespace->dobj.name, 
+                NULL,
+                tbinfo->usename,
                 false, "DEFAULT", q->data, delq->data, NULL,
                 adinfo->dobj.dependencies, adinfo->dobj.nDeps,
                 NULL, NULL);
@@ -6845,6 +6864,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
        ArchiveEntry(fout, indxinfo->dobj.catId, indxinfo->dobj.dumpId,
                     indxinfo->dobj.name,
                     tbinfo->dobj.namespace->dobj.name,
+                    tbinfo->reltablespace,
                     tbinfo->usename, false,
                     "INDEX", q->data, delq->data, NULL,
                     indxinfo->dobj.dependencies, indxinfo->dobj.nDeps,
@@ -6918,14 +6938,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
                              fmtId(attname));
        }
 
-       appendPQExpBuffer(q, ")");
-
-       /* Output tablespace clause if not database's default */
-       if (strlen(indxinfo->tablespace) != 0)
-           appendPQExpBuffer(q, " USING INDEX TABLESPACE %s",
-                             fmtId(indxinfo->tablespace));
-
-       appendPQExpBuffer(q, ";\n");
+       appendPQExpBuffer(q, ");\n");
 
        /* If the index is clustered, we need to record that. */
        if (indxinfo->indisclustered)
@@ -6950,6 +6963,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
        ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
                     coninfo->dobj.name,
                     tbinfo->dobj.namespace->dobj.name,
+                    indxinfo->tablespace,
                     tbinfo->usename, false,
                     "CONSTRAINT", q->data, delq->data, NULL,
                     coninfo->dobj.dependencies, coninfo->dobj.nDeps,
@@ -6981,6 +6995,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
        ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
                     coninfo->dobj.name,
                     tbinfo->dobj.namespace->dobj.name,
+                    NULL,
                     tbinfo->usename, false,
                     "FK CONSTRAINT", q->data, delq->data, NULL,
                     coninfo->dobj.dependencies, coninfo->dobj.nDeps,
@@ -7014,6 +7029,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
            ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
                         coninfo->dobj.name,
                         tbinfo->dobj.namespace->dobj.name,
+                        NULL,
                         tbinfo->usename, false,
                         "CHECK CONSTRAINT", q->data, delq->data, NULL,
                         coninfo->dobj.dependencies, coninfo->dobj.nDeps,
@@ -7048,6 +7064,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
            ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
                         coninfo->dobj.name,
                         tinfo->dobj.namespace->dobj.name,
+                        NULL,
                         tinfo->usename, false,
                         "CHECK CONSTRAINT", q->data, delq->data, NULL,
                         coninfo->dobj.dependencies, coninfo->dobj.nDeps,
@@ -7114,7 +7131,7 @@ setMaxOid(Archive *fout)
             max_oid);
 
    ArchiveEntry(fout, nilCatalogId, createDumpId(),
-                "Max OID", NULL, "",
+                "Max OID", NULL, NULL, "",
                 false, "", sql, "", NULL,
                 NULL, 0,
                 NULL, NULL);
@@ -7313,7 +7330,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
 
        ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
                     tbinfo->dobj.name,
-                    tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
+                    tbinfo->dobj.namespace->dobj.name, 
+                    NULL,
+                    tbinfo->usename,
                     false, "SEQUENCE", query->data, delqry->data, NULL,
                     tbinfo->dobj.dependencies, tbinfo->dobj.nDeps,
                     NULL, NULL);
@@ -7349,7 +7368,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
 
        ArchiveEntry(fout, nilCatalogId, createDumpId(),
                     tbinfo->dobj.name,
-                    tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
+                    tbinfo->dobj.namespace->dobj.name,
+                    NULL,
+                    tbinfo->usename,
                     false, "SEQUENCE SET", query->data, "", NULL,
                     &(tbinfo->dobj.dumpId), 1,
                     NULL, NULL);
@@ -7515,6 +7536,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
    ArchiveEntry(fout, tginfo->dobj.catId, tginfo->dobj.dumpId,
                 tginfo->dobj.name,
                 tbinfo->dobj.namespace->dobj.name,
+                NULL,
                 tbinfo->usename, false,
                 "TRIGGER", query->data, delqry->data, NULL,
                 tginfo->dobj.dependencies, tginfo->dobj.nDeps,
@@ -7609,6 +7631,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
    ArchiveEntry(fout, rinfo->dobj.catId, rinfo->dobj.dumpId,
                 rinfo->dobj.name,
                 tbinfo->dobj.namespace->dobj.name,
+                NULL,
                 tbinfo->usename, false,
                 "RULE", cmd->data, delcmd->data, NULL,
                 rinfo->dobj.dependencies, rinfo->dobj.nDeps,