Skip to content

Commit f23cce7

Browse files
committed
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.
1 parent 533d091 commit f23cce7

File tree

4 files changed

+108
-43
lines changed

4 files changed

+108
-43
lines changed

src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.28 2003/12/06 03:00:11 tgl Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.29 2004/03/24 03:06:08 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -130,7 +130,7 @@ PGconn *ConnectDatabase(Archive *AH,
130130
extern void ArchiveEntry(Archive *AHX,
131131
CatalogId catalogId, DumpId dumpId,
132132
const char *tag,
133-
const char *namespace, const char *owner,
133+
const char *namespace, const char *owner, bool withOids,
134134
const char *desc, const char *defn,
135135
const char *dropStmt, const char *copyStmt,
136136
const DumpId *deps, int nDeps,

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.84 2004/03/03 21:28:54 tgl Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.85 2004/03/24 03:06:08 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -53,6 +53,7 @@ static void fixPriorBlobRefs(ArchiveHandle *AH, TocEntry *blobte,
5353
RestoreOptions *ropt);
5454
static void _doSetFixedOutputState(ArchiveHandle *AH);
5555
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
56+
static void _doSetWithOids(ArchiveHandle *AH, const bool withOids);
5657
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user);
5758
static void _becomeUser(ArchiveHandle *AH, const char *user);
5859
static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
@@ -254,6 +255,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
254255
if ((reqs & REQ_SCHEMA) != 0) /* We want the schema */
255256
{
256257
ahlog(AH, 1, "creating %s %s\n", te->desc, te->tag);
258+
257259
_printTocEntry(AH, te, ropt, false);
258260
defnDumped = true;
259261

@@ -559,7 +561,7 @@ void
559561
ArchiveEntry(Archive *AHX,
560562
CatalogId catalogId, DumpId dumpId,
561563
const char *tag,
562-
const char *namespace, const char *owner,
564+
const char *namespace, const char *owner, bool withOids,
563565
const char *desc, const char *defn,
564566
const char *dropStmt, const char *copyStmt,
565567
const DumpId *deps, int nDeps,
@@ -587,6 +589,7 @@ ArchiveEntry(Archive *AHX,
587589
newToc->tag = strdup(tag);
588590
newToc->namespace = namespace ? strdup(namespace) : NULL;
589591
newToc->owner = strdup(owner);
592+
newToc->withOids = withOids;
590593
newToc->desc = strdup(desc);
591594
newToc->defn = strdup(defn);
592595
newToc->dropStmt = strdup(dropStmt);
@@ -1597,7 +1600,8 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
15971600
AH->currUser = strdup(""); /* So it's valid, but we can free() it
15981601
* later if necessary */
15991602
AH->currSchema = strdup(""); /* ditto */
1600-
1603+
AH->currWithOids = -1; /* force SET */
1604+
16011605
AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
16021606
if (!AH->toc)
16031607
die_horribly(AH, modulename, "out of memory\n");
@@ -1727,6 +1731,7 @@ WriteToc(ArchiveHandle *AH)
17271731
WriteStr(AH, te->copyStmt);
17281732
WriteStr(AH, te->namespace);
17291733
WriteStr(AH, te->owner);
1734+
WriteStr(AH, te->withOids ? "true" : "false");
17301735

17311736
/* Dump list of dependencies */
17321737
for (i = 0; i < te->nDeps; i++)
@@ -1795,7 +1800,16 @@ ReadToc(ArchiveHandle *AH)
17951800
te->namespace = ReadStr(AH);
17961801

17971802
te->owner = ReadStr(AH);
1798-
1803+
if (AH->version >= K_VERS_1_9)
1804+
{
1805+
if (strcmp(ReadStr(AH), "true") == 0)
1806+
te->withOids = true;
1807+
else
1808+
te->withOids = false;
1809+
}
1810+
else
1811+
te->withOids = true;
1812+
17991813
/* Read TOC entry dependencies */
18001814
if (AH->version >= K_VERS_1_5)
18011815
{
@@ -2009,6 +2023,37 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
20092023
}
20102024

20112025

2026+
/*
2027+
* Issue a SET default_with_oids command. Caller is responsible
2028+
* for updating state if appropriate.
2029+
*/
2030+
static void
2031+
_doSetWithOids(ArchiveHandle *AH, const bool withOids)
2032+
{
2033+
PQExpBuffer cmd = createPQExpBuffer();
2034+
2035+
appendPQExpBuffer(cmd, "SET default_with_oids = %s;", withOids ?
2036+
"true" : "false");
2037+
2038+
if (RestoringToDB(AH))
2039+
{
2040+
PGresult *res;
2041+
2042+
res = PQexec(AH->connection, cmd->data);
2043+
2044+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
2045+
die_horribly(AH, modulename, "could not set default_with_oids: %s",
2046+
PQerrorMessage(AH->connection));
2047+
2048+
PQclear(res);
2049+
}
2050+
else
2051+
ahprintf(AH, "%s\n\n", cmd->data);
2052+
2053+
destroyPQExpBuffer(cmd);
2054+
}
2055+
2056+
20122057
/*
20132058
* Issue the commands to connect to the specified database
20142059
* as the specified user.
@@ -2049,7 +2094,8 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
20492094
if (AH->currSchema)
20502095
free(AH->currSchema);
20512096
AH->currSchema = strdup("");
2052-
2097+
AH->currWithOids = -1;
2098+
20532099
/* re-establish fixed state */
20542100
_doSetFixedOutputState(AH);
20552101
}
@@ -2094,6 +2140,20 @@ _becomeOwner(ArchiveHandle *AH, TocEntry *te)
20942140
}
20952141

20962142

2143+
/*
2144+
* Set the proper default_with_oids value for the table.
2145+
*/
2146+
static void
2147+
_setWithOids(ArchiveHandle *AH, TocEntry *te)
2148+
{
2149+
if (AH->currWithOids != te->withOids)
2150+
{
2151+
_doSetWithOids(AH, te->withOids);
2152+
AH->currWithOids = te->withOids;
2153+
}
2154+
}
2155+
2156+
20972157
/*
20982158
* Issue the commands to select the specified schema as the current schema
20992159
* in the target database.
@@ -2146,6 +2206,8 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
21462206
/* Select owner and schema as necessary */
21472207
_becomeOwner(AH, te);
21482208
_selectOutputSchema(AH, te->namespace);
2209+
if (strcmp(te->desc, "TABLE") == 0)
2210+
_setWithOids(AH, te);
21492211

21502212
if (isData)
21512213
pfx = "Data for ";

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.56 2004/02/24 03:35:19 tgl Exp $
20+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.57 2004/03/24 03:06:08 momjian Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
6262
#endif
6363

6464
#define K_VERS_MAJOR 1
65-
#define K_VERS_MINOR 8
65+
#define K_VERS_MINOR 9
6666
#define K_VERS_REV 0
6767

6868
/* Data block types */
@@ -80,8 +80,9 @@ typedef z_stream *z_streamp;
8080
#define K_VERS_1_7 (( (1 * 256 + 7) * 256 + 0) * 256 + 0) /* File Offset size in
8181
* header */
8282
#define K_VERS_1_8 (( (1 * 256 + 8) * 256 + 0) * 256 + 0) /* change interpretation of ID numbers and dependencies */
83+
#define K_VERS_1_9 (( (1 * 256 + 9) * 256 + 0) * 256 + 0) /* add default_with_oids tracking */
8384

84-
#define K_VERS_MAX (( (1 * 256 + 8) * 256 + 255) * 256 + 0)
85+
#define K_VERS_MAX (( (1 * 256 + 9) * 256 + 255) * 256 + 0)
8586

8687
/* No of BLOBs to restore in 1 TX */
8788
#define BLOB_BATCH_SIZE 100
@@ -245,7 +246,8 @@ typedef struct _archiveHandle
245246
/* these vars track state to avoid sending redundant SET commands */
246247
char *currUser; /* current username */
247248
char *currSchema; /* current schema */
248-
249+
bool currWithOids; /* current default_with_oids setting */
250+
249251
void *lo_buf;
250252
size_t lo_buf_used;
251253
size_t lo_buf_size;
@@ -262,6 +264,7 @@ typedef struct _tocEntry
262264
char *tag; /* index tag */
263265
char *namespace; /* null or empty string if not in a schema */
264266
char *owner;
267+
bool withOids; /* Used only by "TABLE" tags */
265268
char *desc;
266269
char *defn;
267270
char *dropStmt;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy