Commit f23cce73 authored by Bruce Momjian's avatar Bruce Momjian

Use the new GUC variable default_with_oids in pg_dump, rather than using

WITH/WITHOUT OIDS in dump files.  This makes dump files more portable.

I have updated the pg_dump version so old binary dumps will load fine.

Pre-7.5 dumps use WITHOUT OIDS in SQL were needed, so they should be
fine.
parent 533d0915
......@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.28 2003/12/06 03:00:11 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.29 2004/03/24 03:06:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -130,7 +130,7 @@ PGconn *ConnectDatabase(Archive *AH,
extern void 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,
......
......@@ -15,7 +15,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -53,6 +53,7 @@ static void fixPriorBlobRefs(ArchiveHandle *AH, TocEntry *blobte,
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);
......@@ -254,6 +255,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
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;
......@@ -559,7 +561,7 @@ void
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,
......@@ -587,6 +589,7 @@ ArchiveEntry(Archive *AHX,
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);
......@@ -1597,7 +1600,8 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
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");
......@@ -1727,6 +1731,7 @@ WriteToc(ArchiveHandle *AH)
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++)
......@@ -1795,7 +1800,16 @@ ReadToc(ArchiveHandle *AH)
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)
{
......@@ -2009,6 +2023,37 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
}
/*
* 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.
......@@ -2049,7 +2094,8 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
if (AH->currSchema)
free(AH->currSchema);
AH->currSchema = strdup("");
AH->currWithOids = -1;
/* re-establish fixed state */
_doSetFixedOutputState(AH);
}
......@@ -2094,6 +2140,20 @@ _becomeOwner(ArchiveHandle *AH, TocEntry *te)
}
/*
* 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.
......@@ -2146,6 +2206,8 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
/* 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 ";
......
......@@ -17,7 +17,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.56 2004/02/24 03:35:19 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.57 2004/03/24 03:06:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
#endif
#define K_VERS_MAJOR 1
#define K_VERS_MINOR 8
#define K_VERS_MINOR 9
#define K_VERS_REV 0
/* Data block types */
......@@ -80,8 +80,9 @@ typedef z_stream *z_streamp;
#define K_VERS_1_7 (( (1 * 256 + 7) * 256 + 0) * 256 + 0) /* File Offset size in
* header */
#define K_VERS_1_8 (( (1 * 256 + 8) * 256 + 0) * 256 + 0) /* change interpretation of ID numbers and dependencies */
#define K_VERS_1_9 (( (1 * 256 + 9) * 256 + 0) * 256 + 0) /* add default_with_oids tracking */
#define K_VERS_MAX (( (1 * 256 + 8) * 256 + 255) * 256 + 0)
#define K_VERS_MAX (( (1 * 256 + 9) * 256 + 255) * 256 + 0)
/* No of BLOBs to restore in 1 TX */
#define BLOB_BATCH_SIZE 100
......@@ -245,7 +246,8 @@ typedef struct _archiveHandle
/* these vars track state to avoid sending redundant SET commands */
char *currUser; /* current username */
char *currSchema; /* current schema */
bool currWithOids; /* current default_with_oids setting */
void *lo_buf;
size_t lo_buf_used;
size_t lo_buf_size;
......@@ -262,6 +264,7 @@ typedef struct _tocEntry
char *tag; /* index tag */
char *namespace; /* null or empty string if not in a schema */
char *owner;
bool withOids; /* Used only by "TABLE" tags */
char *desc;
char *defn;
char *dropStmt;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment