Commit 04baa0eb authored by Tom Lane's avatar Tom Lane

Update pg_dump to use SET DEFAULT_TABLESPACE instead of explicit

tablespace clauses; this should improve compatibility of dump files.
Philip Warner, some rework by Tom Lane.
parent 1d13bed7
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * 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 ...@@ -54,8 +54,10 @@ typedef enum _archiveFormat
typedef struct _Archive typedef struct _Archive
{ {
int verbose; int verbose;
int remoteVersion; char *remoteVersionStr; /* server's version string */
int minRemoteVersion; int remoteVersion; /* same in numeric form */
int minRemoteVersion; /* allowable range */
int maxRemoteVersion; int maxRemoteVersion;
/* error handling */ /* error handling */
...@@ -139,7 +141,8 @@ PGconn *ConnectDatabase(Archive *AH, ...@@ -139,7 +141,8 @@ PGconn *ConnectDatabase(Archive *AH,
extern void ArchiveEntry(Archive *AHX, extern void ArchiveEntry(Archive *AHX,
CatalogId catalogId, DumpId dumpId, CatalogId catalogId, DumpId dumpId,
const char *tag, 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 *desc, const char *defn,
const char *dropStmt, const char *copyStmt, const char *dropStmt, const char *copyStmt,
const DumpId *deps, int nDeps, const DumpId *deps, int nDeps,
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * 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); ...@@ -60,6 +60,7 @@ static void _reconnectToDB(ArchiveHandle *AH, const char *dbname);
static void _becomeUser(ArchiveHandle *AH, const char *user); static void _becomeUser(ArchiveHandle *AH, const char *user);
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te); static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName); 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 teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool acl_pass);
static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
...@@ -602,7 +603,9 @@ void ...@@ -602,7 +603,9 @@ void
ArchiveEntry(Archive *AHX, ArchiveEntry(Archive *AHX,
CatalogId catalogId, DumpId dumpId, CatalogId catalogId, DumpId dumpId,
const char *tag, 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 *desc, const char *defn,
const char *dropStmt, const char *copyStmt, const char *dropStmt, const char *copyStmt,
const DumpId *deps, int nDeps, const DumpId *deps, int nDeps,
...@@ -629,6 +632,7 @@ ArchiveEntry(Archive *AHX, ...@@ -629,6 +632,7 @@ ArchiveEntry(Archive *AHX,
newToc->tag = strdup(tag); newToc->tag = strdup(tag);
newToc->namespace = namespace ? strdup(namespace) : NULL; newToc->namespace = namespace ? strdup(namespace) : NULL;
newToc->tablespace = tablespace ? strdup(tablespace) : NULL;
newToc->owner = strdup(owner); newToc->owner = strdup(owner);
newToc->withOids = withOids; newToc->withOids = withOids;
newToc->desc = strdup(desc); newToc->desc = strdup(desc);
...@@ -693,6 +697,12 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt) ...@@ -693,6 +697,12 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
ahprintf(AH, "; Format: %s\n", fmtName); ahprintf(AH, "; Format: %s\n", fmtName);
ahprintf(AH, "; Integer: %d bytes\n", (int) AH->intSize); ahprintf(AH, "; Integer: %d bytes\n", (int) AH->intSize);
ahprintf(AH, "; Offset: %d bytes\n", (int) AH->offSize); 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"); ahprintf(AH, ";\n;\n; Selected TOC Entries:\n;\n");
...@@ -1822,6 +1832,7 @@ WriteToc(ArchiveHandle *AH) ...@@ -1822,6 +1832,7 @@ WriteToc(ArchiveHandle *AH)
WriteStr(AH, te->dropStmt); WriteStr(AH, te->dropStmt);
WriteStr(AH, te->copyStmt); WriteStr(AH, te->copyStmt);
WriteStr(AH, te->namespace); WriteStr(AH, te->namespace);
WriteStr(AH, te->tablespace);
WriteStr(AH, te->owner); WriteStr(AH, te->owner);
WriteStr(AH, te->withOids ? "true" : "false"); WriteStr(AH, te->withOids ? "true" : "false");
...@@ -1891,6 +1902,9 @@ ReadToc(ArchiveHandle *AH) ...@@ -1891,6 +1902,9 @@ ReadToc(ArchiveHandle *AH)
if (AH->version >= K_VERS_1_6) if (AH->version >= K_VERS_1_6)
te->namespace = ReadStr(AH); te->namespace = ReadStr(AH);
if (AH->version >= K_VERS_1_10)
te->tablespace = ReadStr(AH);
te->owner = ReadStr(AH); te->owner = ReadStr(AH);
if (AH->version >= K_VERS_1_9) if (AH->version >= K_VERS_1_9)
{ {
...@@ -2293,6 +2307,61 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName) ...@@ -2293,6 +2307,61 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
destroyPQExpBuffer(qry); 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 * Parses the dropStmt part of a TOC entry and returns
...@@ -2378,9 +2447,10 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat ...@@ -2378,9 +2447,10 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
strcmp(te->desc, "SCHEMA") == 0 && strcmp(te->tag, "public") == 0) strcmp(te->desc, "SCHEMA") == 0 && strcmp(te->tag, "public") == 0)
return; return;
/* Select owner and schema as necessary */ /* Select owner, schema, and tablespace as necessary */
_becomeOwner(AH, te); _becomeOwner(AH, te);
_selectOutputSchema(AH, te->namespace); _selectOutputSchema(AH, te->namespace);
_selectTablespace(AH, te->tablespace);
/* Set up OID mode too */ /* Set up OID mode too */
if (strcmp(te->desc, "TABLE") == 0) if (strcmp(te->desc, "TABLE") == 0)
...@@ -2411,10 +2481,14 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat ...@@ -2411,10 +2481,14 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
ahprintf(AH, "\n"); 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, pfx, te->tag, te->desc,
te->namespace ? te->namespace : "-", te->namespace ? te->namespace : "-",
te->owner); te->owner);
if (te->tablespace)
ahprintf(AH, "; Tablespace: %s", te->tablespace);
ahprintf(AH, "\n");
if (AH->PrintExtraTocPtr != NULL) if (AH->PrintExtraTocPtr != NULL)
(*AH->PrintExtraTocPtr) (AH, te); (*AH->PrintExtraTocPtr) (AH, te);
ahprintf(AH, "--\n\n"); ahprintf(AH, "--\n\n");
...@@ -2509,6 +2583,8 @@ WriteHead(ArchiveHandle *AH) ...@@ -2509,6 +2583,8 @@ WriteHead(ArchiveHandle *AH)
WriteInt(AH, crtm.tm_year); WriteInt(AH, crtm.tm_year);
WriteInt(AH, crtm.tm_isdst); WriteInt(AH, crtm.tm_isdst);
WriteStr(AH, PQdb(AH->connection)); WriteStr(AH, PQdb(AH->connection));
WriteStr(AH, AH->public.remoteVersionStr);
WriteStr(AH, PG_VERSION);
} }
void void
...@@ -2595,6 +2671,12 @@ ReadHead(ArchiveHandle *AH) ...@@ -2595,6 +2671,12 @@ ReadHead(ArchiveHandle *AH)
write_msg(modulename, "WARNING: invalid creation date in header\n"); 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);
}
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
* *
* IDENTIFICATION * 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; ...@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
#endif #endif
#define K_VERS_MAJOR 1 #define K_VERS_MAJOR 1
#define K_VERS_MINOR 9 #define K_VERS_MINOR 10
#define K_VERS_REV 0 #define K_VERS_REV 0
/* Data block types */ /* Data block types */
...@@ -84,8 +84,9 @@ typedef z_stream *z_streamp; ...@@ -84,8 +84,9 @@ typedef z_stream *z_streamp;
* dependencies */ * dependencies */
#define K_VERS_1_9 (( (1 * 256 + 9) * 256 + 0) * 256 + 0) /* add default_with_oids #define K_VERS_1_9 (( (1 * 256 + 9) * 256 + 0) * 256 + 0) /* add default_with_oids
* tracking */ * 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 */ /* No of BLOBs to restore in 1 TX */
#define BLOB_BATCH_SIZE 100 #define BLOB_BATCH_SIZE 100
...@@ -171,6 +172,11 @@ typedef struct _archiveHandle ...@@ -171,6 +172,11 @@ typedef struct _archiveHandle
char vrev; char vrev;
int version; /* Conveniently formatted version */ 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 int debugLevel; /* Used for logging (currently only by
* --verbose) */ * --verbose) */
size_t intSize; /* Size of an integer in the archive */ size_t intSize; /* Size of an integer in the archive */
...@@ -260,6 +266,7 @@ typedef struct _archiveHandle ...@@ -260,6 +266,7 @@ typedef struct _archiveHandle
/* these vars track state to avoid sending redundant SET commands */ /* these vars track state to avoid sending redundant SET commands */
char *currUser; /* current username */ char *currUser; /* current username */
char *currSchema; /* current schema */ char *currSchema; /* current schema */
char *currTablespace; /* current tablespace */
bool currWithOids; /* current default_with_oids setting */ bool currWithOids; /* current default_with_oids setting */
void *lo_buf; void *lo_buf;
...@@ -283,6 +290,8 @@ typedef struct _tocEntry ...@@ -283,6 +290,8 @@ typedef struct _tocEntry
* (used in restore) */ * (used in restore) */
char *tag; /* index tag */ char *tag; /* index tag */
char *namespace; /* null or empty string if not in a schema */ 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; char *owner;
bool withOids; /* Used only by "TABLE" tags */ bool withOids; /* Used only by "TABLE" tags */
char *desc; char *desc;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver. * Implements the basic DB functions used by the archiver.
* *
* IDENTIFICATION * 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) ...@@ -69,6 +69,7 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
remoteversion = _parse_version(AH, remoteversion_str); remoteversion = _parse_version(AH, remoteversion_str);
AH->public.remoteVersionStr = strdup(remoteversion_str);
AH->public.remoteVersion = remoteversion; AH->public.remoteVersion = remoteversion;
if (myversion != remoteversion if (myversion != remoteversion
......
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