*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.84 2004/03/03 21:28:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.85 2004/03/24 03:06:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
RestoreOptions *ropt);
static void _doSetFixedOutputState(ArchiveHandle *AH);
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
+static void _doSetWithOids(ArchiveHandle *AH, const bool withOids);
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user);
static void _becomeUser(ArchiveHandle *AH, const char *user);
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
if ((reqs & REQ_SCHEMA) != 0) /* We want the schema */
{
ahlog(AH, 1, "creating %s %s\n", te->desc, te->tag);
+
_printTocEntry(AH, te, ropt, false);
defnDumped = true;
ArchiveEntry(Archive *AHX,
CatalogId catalogId, DumpId dumpId,
const char *tag,
- const char *namespace, const char *owner,
+ const char *namespace, const char *owner, bool withOids,
const char *desc, const char *defn,
const char *dropStmt, const char *copyStmt,
const DumpId *deps, int nDeps,
newToc->tag = strdup(tag);
newToc->namespace = namespace ? strdup(namespace) : NULL;
newToc->owner = strdup(owner);
+ newToc->withOids = withOids;
newToc->desc = strdup(desc);
newToc->defn = strdup(defn);
newToc->dropStmt = strdup(dropStmt);
AH->currUser = strdup(""); /* So it's valid, but we can free() it
* later if necessary */
AH->currSchema = strdup(""); /* ditto */
-
+ AH->currWithOids = -1; /* force SET */
+
AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
if (!AH->toc)
die_horribly(AH, modulename, "out of memory\n");
WriteStr(AH, te->copyStmt);
WriteStr(AH, te->namespace);
WriteStr(AH, te->owner);
+ WriteStr(AH, te->withOids ? "true" : "false");
/* Dump list of dependencies */
for (i = 0; i < te->nDeps; i++)
te->namespace = ReadStr(AH);
te->owner = ReadStr(AH);
-
+ if (AH->version >= K_VERS_1_9)
+ {
+ if (strcmp(ReadStr(AH), "true") == 0)
+ te->withOids = true;
+ else
+ te->withOids = false;
+ }
+ else
+ te->withOids = true;
+
/* Read TOC entry dependencies */
if (AH->version >= K_VERS_1_5)
{
}
+/*
+ * Issue a SET default_with_oids command. Caller is responsible
+ * for updating state if appropriate.
+ */
+static void
+_doSetWithOids(ArchiveHandle *AH, const bool withOids)
+{
+ PQExpBuffer cmd = createPQExpBuffer();
+
+ appendPQExpBuffer(cmd, "SET default_with_oids = %s;", withOids ?
+ "true" : "false");
+
+ if (RestoringToDB(AH))
+ {
+ PGresult *res;
+
+ res = PQexec(AH->connection, cmd->data);
+
+ if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
+ die_horribly(AH, modulename, "could not set default_with_oids: %s",
+ PQerrorMessage(AH->connection));
+
+ PQclear(res);
+ }
+ else
+ ahprintf(AH, "%s\n\n", cmd->data);
+
+ destroyPQExpBuffer(cmd);
+}
+
+
/*
* Issue the commands to connect to the specified database
* as the specified user.
if (AH->currSchema)
free(AH->currSchema);
AH->currSchema = strdup("");
-
+ AH->currWithOids = -1;
+
/* re-establish fixed state */
_doSetFixedOutputState(AH);
}
}
+/*
+ * Set the proper default_with_oids value for the table.
+ */
+static void
+_setWithOids(ArchiveHandle *AH, TocEntry *te)
+{
+ if (AH->currWithOids != te->withOids)
+ {
+ _doSetWithOids(AH, te->withOids);
+ AH->currWithOids = te->withOids;
+ }
+}
+
+
/*
* Issue the commands to select the specified schema as the current schema
* in the target database.
/* Select owner and schema as necessary */
_becomeOwner(AH, te);
_selectOutputSchema(AH, te->namespace);
+ if (strcmp(te->desc, "TABLE") == 0)
+ _setWithOids(AH, te);
if (isData)
pfx = "Data for ";
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.369 2004/03/23 22:06:08 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.370 2004/03/24 03:06:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
ArchiveEntry(fout, tdinfo->dobj.catId, tdinfo->dobj.dumpId,
tbinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
- tbinfo->usename,
+ tbinfo->usename, false,
"TABLE DATA", "", "", copyStmt,
tdinfo->dobj.dependencies, tdinfo->dobj.nDeps,
dumpFn, tdinfo);
datname, /* Name */
NULL, /* Namespace */
dba, /* Owner */
+ false, /* with oids */
"DATABASE", /* Desc */
creaQry->data, /* Create */
delQry->data, /* Del */
ArchiveEntry(AH, nilCatalogId, createDumpId(),
"ENCODING", NULL, "",
- "ENCODING", qry->data, "", NULL,
+ false, "ENCODING", qry->data, "", NULL,
NULL, 0,
NULL, NULL);
appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, nilCatalogId, createDumpId(),
- target, namespace, owner,
+ target, namespace, owner, false,
"COMMENT", query->data, "", NULL,
&(dumpId), 1,
NULL, NULL);
ArchiveEntry(fout, nilCatalogId, createDumpId(),
target->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
- "COMMENT", query->data, "", NULL,
+ false, "COMMENT", query->data, "", NULL,
&(tbinfo->dobj.dumpId), 1,
NULL, NULL);
}
ArchiveEntry(fout, nilCatalogId, createDumpId(),
target->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
- "COMMENT", query->data, "", NULL,
+ false, "COMMENT", query->data, "", NULL,
&(tbinfo->dobj.dumpId), 1,
NULL, NULL);
}
case DO_BLOBS:
ArchiveEntry(fout, dobj->catId, dobj->dumpId,
dobj->name, NULL, "",
- "BLOBS", "", "", NULL,
+ false, "BLOBS", "", "", NULL,
NULL, 0,
dumpBlobs, NULL);
break;
ArchiveEntry(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId,
nspinfo->dobj.name,
NULL, "",
- "SCHEMA", q->data, delq->data, NULL,
+ false, "SCHEMA", q->data, delq->data, NULL,
nspinfo->dobj.dependencies, nspinfo->dobj.nDeps,
NULL, NULL);
}
ArchiveEntry(fout, tinfo->dobj.catId, tinfo->dobj.dumpId,
tinfo->dobj.name,
tinfo->dobj.namespace->dobj.name,
- tinfo->usename,
+ tinfo->usename, false,
"TYPE", q->data, delq->data, NULL,
tinfo->dobj.dependencies, tinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, tinfo->dobj.catId, tinfo->dobj.dumpId,
tinfo->dobj.name,
tinfo->dobj.namespace->dobj.name,
- tinfo->usename,
+ tinfo->usename, false,
"DOMAIN", q->data, delq->data, NULL,
tinfo->dobj.dependencies, tinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, tinfo->dobj.catId, tinfo->dobj.dumpId,
tinfo->dobj.name,
tinfo->dobj.namespace->dobj.name,
- tinfo->usename,
+ tinfo->usename, false,
"TYPE", q->data, delq->data, NULL,
tinfo->dobj.dependencies, tinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
plang->dobj.name,
funcInfo->dobj.namespace->dobj.name, "",
- "PROCEDURAL LANGUAGE",
+ false, "PROCEDURAL LANGUAGE",
defqry->data, delqry->data, NULL,
plang->dobj.dependencies, plang->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId,
funcsig_tag,
finfo->dobj.namespace->dobj.name,
- finfo->usename,
+ finfo->usename, false,
"FUNCTION", q->data, delqry->data, NULL,
finfo->dobj.dependencies, finfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
castsig->data,
"pg_catalog", "",
- "CAST", defqry->data, delqry->data, NULL,
+ false, "CAST", defqry->data, delqry->data, NULL,
cast->dobj.dependencies, cast->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, oprinfo->dobj.catId, oprinfo->dobj.dumpId,
oprinfo->dobj.name,
oprinfo->dobj.namespace->dobj.name, oprinfo->usename,
- "OPERATOR", q->data, delq->data, NULL,
+ false, "OPERATOR", q->data, delq->data, NULL,
oprinfo->dobj.dependencies, oprinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, opcinfo->dobj.catId, opcinfo->dobj.dumpId,
opcinfo->dobj.name,
opcinfo->dobj.namespace->dobj.name, opcinfo->usename,
- "OPERATOR CLASS", q->data, delq->data, NULL,
+ false, "OPERATOR CLASS", q->data, delq->data, NULL,
opcinfo->dobj.dependencies, opcinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
convinfo->dobj.name,
convinfo->dobj.namespace->dobj.name, convinfo->usename,
- "CONVERSION", q->data, delq->data, NULL,
+ false, "CONVERSION", q->data, delq->data, NULL,
convinfo->dobj.dependencies, convinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
aggsig_tag,
agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.usename,
- "AGGREGATE", q->data, delq->data, NULL,
+ false, "AGGREGATE", q->data, delq->data, NULL,
agginfo->aggfn.dobj.dependencies, agginfo->aggfn.dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, nilCatalogId, createDumpId(),
tag, nspname,
owner ? owner : "",
- "ACL", sql->data, "", NULL,
+ false, "ACL", sql->data, "", NULL,
&(objDumpId), 1,
NULL, NULL);
appendPQExpBuffer(q, ")");
}
- appendPQExpBuffer(q, tbinfo->hasoids ? " WITH OIDS" : " WITHOUT OIDS");
-
appendPQExpBuffer(q, ";\n");
/* Loop dumping statistics and storage statements */
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,
reltypename, q->data, delq->data, NULL,
tbinfo->dobj.dependencies, tbinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
tbinfo->attnames[adnum - 1],
tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
- "DEFAULT", q->data, delq->data, NULL,
+ false, "DEFAULT", q->data, delq->data, NULL,
adinfo->dobj.dependencies, adinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, indxinfo->dobj.catId, indxinfo->dobj.dumpId,
indxinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
- tbinfo->usename,
+ tbinfo->usename, false,
"INDEX", q->data, delq->data, NULL,
indxinfo->dobj.dependencies, indxinfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
- tbinfo->usename,
+ tbinfo->usename, false,
"CONSTRAINT", q->data, delq->data, NULL,
coninfo->dobj.dependencies, coninfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
- tbinfo->usename,
+ tbinfo->usename, false,
"FK CONSTRAINT", q->data, delq->data, NULL,
coninfo->dobj.dependencies, coninfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
- tbinfo->usename,
+ tbinfo->usename, false,
"CHECK CONSTRAINT", q->data, delq->data, NULL,
coninfo->dobj.dependencies, coninfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tinfo->dobj.namespace->dobj.name,
- tinfo->usename,
+ tinfo->usename, false,
"CHECK CONSTRAINT", q->data, delq->data, NULL,
coninfo->dobj.dependencies, coninfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, nilCatalogId, createDumpId(),
"Max OID", NULL, "",
- "<Init>", sql, "", NULL,
+ false, "<Init>", sql, "", NULL,
NULL, 0,
NULL, NULL);
}
ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
tbinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
- "SEQUENCE", query->data, delqry->data, NULL,
+ false, "SEQUENCE", query->data, delqry->data, NULL,
tbinfo->dobj.dependencies, tbinfo->dobj.nDeps,
NULL, NULL);
}
ArchiveEntry(fout, nilCatalogId, createDumpId(),
tbinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name, tbinfo->usename,
- "SEQUENCE SET", query->data, "", NULL,
+ false, "SEQUENCE SET", query->data, "", NULL,
&(tbinfo->dobj.dumpId), 1,
NULL, NULL);
}
ArchiveEntry(fout, tginfo->dobj.catId, tginfo->dobj.dumpId,
tginfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
- tbinfo->usename,
+ tbinfo->usename, false,
"TRIGGER", query->data, delqry->data, NULL,
tginfo->dobj.dependencies, tginfo->dobj.nDeps,
NULL, NULL);
ArchiveEntry(fout, rinfo->dobj.catId, rinfo->dobj.dumpId,
rinfo->dobj.name,
tbinfo->dobj.namespace->dobj.name,
- tbinfo->usename,
+ tbinfo->usename, false,
"RULE", cmd->data, delcmd->data, NULL,
rinfo->dobj.dependencies, rinfo->dobj.nDeps,
NULL, NULL);