|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * 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 $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -53,6 +53,7 @@ static void fixPriorBlobRefs(ArchiveHandle *AH, TocEntry *blobte,
|
53 | 53 | RestoreOptions *ropt);
|
54 | 54 | static void _doSetFixedOutputState(ArchiveHandle *AH);
|
55 | 55 | static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
|
| 56 | +static void _doSetWithOids(ArchiveHandle *AH, const bool withOids); |
56 | 57 | static void _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user);
|
57 | 58 | static void _becomeUser(ArchiveHandle *AH, const char *user);
|
58 | 59 | static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
|
@@ -254,6 +255,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
|
254 | 255 | if ((reqs & REQ_SCHEMA) != 0) /* We want the schema */
|
255 | 256 | {
|
256 | 257 | ahlog(AH, 1, "creating %s %s\n", te->desc, te->tag);
|
| 258 | + |
257 | 259 | _printTocEntry(AH, te, ropt, false);
|
258 | 260 | defnDumped = true;
|
259 | 261 |
|
|
559 | 561 | ArchiveEntry(Archive *AHX,
|
560 | 562 | CatalogId catalogId, DumpId dumpId,
|
561 | 563 | const char *tag,
|
562 |
| - const char *namespace, const char *owner, |
| 564 | + const char *namespace, const char *owner, bool withOids, |
563 | 565 | const char *desc, const char *defn,
|
564 | 566 | const char *dropStmt, const char *copyStmt,
|
565 | 567 | const DumpId *deps, int nDeps,
|
@@ -587,6 +589,7 @@ ArchiveEntry(Archive *AHX,
|
587 | 589 | newToc->tag = strdup(tag);
|
588 | 590 | newToc->namespace = namespace ? strdup(namespace) : NULL;
|
589 | 591 | newToc->owner = strdup(owner);
|
| 592 | + newToc->withOids = withOids; |
590 | 593 | newToc->desc = strdup(desc);
|
591 | 594 | newToc->defn = strdup(defn);
|
592 | 595 | newToc->dropStmt = strdup(dropStmt);
|
@@ -1597,7 +1600,8 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
|
1597 | 1600 | AH->currUser = strdup(""); /* So it's valid, but we can free() it
|
1598 | 1601 | * later if necessary */
|
1599 | 1602 | AH->currSchema = strdup(""); /* ditto */
|
1600 |
| - |
| 1603 | + AH->currWithOids = -1; /* force SET */ |
| 1604 | + |
1601 | 1605 | AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
|
1602 | 1606 | if (!AH->toc)
|
1603 | 1607 | die_horribly(AH, modulename, "out of memory\n");
|
@@ -1727,6 +1731,7 @@ WriteToc(ArchiveHandle *AH)
|
1727 | 1731 | WriteStr(AH, te->copyStmt);
|
1728 | 1732 | WriteStr(AH, te->namespace);
|
1729 | 1733 | WriteStr(AH, te->owner);
|
| 1734 | + WriteStr(AH, te->withOids ? "true" : "false"); |
1730 | 1735 |
|
1731 | 1736 | /* Dump list of dependencies */
|
1732 | 1737 | for (i = 0; i < te->nDeps; i++)
|
@@ -1795,7 +1800,16 @@ ReadToc(ArchiveHandle *AH)
|
1795 | 1800 | te->namespace = ReadStr(AH);
|
1796 | 1801 |
|
1797 | 1802 | 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 | + |
1799 | 1813 | /* Read TOC entry dependencies */
|
1800 | 1814 | if (AH->version >= K_VERS_1_5)
|
1801 | 1815 | {
|
@@ -2009,6 +2023,37 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
|
2009 | 2023 | }
|
2010 | 2024 |
|
2011 | 2025 |
|
| 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 | + |
2012 | 2057 | /*
|
2013 | 2058 | * Issue the commands to connect to the specified database
|
2014 | 2059 | * as the specified user.
|
@@ -2049,7 +2094,8 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user)
|
2049 | 2094 | if (AH->currSchema)
|
2050 | 2095 | free(AH->currSchema);
|
2051 | 2096 | AH->currSchema = strdup("");
|
2052 |
| - |
| 2097 | + AH->currWithOids = -1; |
| 2098 | + |
2053 | 2099 | /* re-establish fixed state */
|
2054 | 2100 | _doSetFixedOutputState(AH);
|
2055 | 2101 | }
|
@@ -2094,6 +2140,20 @@ _becomeOwner(ArchiveHandle *AH, TocEntry *te)
|
2094 | 2140 | }
|
2095 | 2141 |
|
2096 | 2142 |
|
| 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 | + |
2097 | 2157 | /*
|
2098 | 2158 | * Issue the commands to select the specified schema as the current schema
|
2099 | 2159 | * in the target database.
|
@@ -2146,6 +2206,8 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
|
2146 | 2206 | /* Select owner and schema as necessary */
|
2147 | 2207 | _becomeOwner(AH, te);
|
2148 | 2208 | _selectOutputSchema(AH, te->namespace);
|
| 2209 | + if (strcmp(te->desc, "TABLE") == 0) |
| 2210 | + _setWithOids(AH, te); |
2149 | 2211 |
|
2150 | 2212 | if (isData)
|
2151 | 2213 | pfx = "Data for ";
|
|
0 commit comments