Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bb30d49

Browse files
committed
- Don't dump COMMENTs in data-only dumps
- Fix view dumping SQL for V7.0 - Fix bug when getting view oid with long view names - Treat SEQUENCE SET TOC entries as data entries rather than schema entries. - Make allowance for data entries that did not have a data dumper routine (eg. SEQUENCE SET)
1 parent 5e19e14 commit bb30d49

File tree

3 files changed

+122
-66
lines changed

3 files changed

+122
-66
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 82 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.25 2001/04/25 07:03:19 pjw Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.26 2001/05/12 01:03:59 pjw Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -51,6 +51,12 @@
5151
* - Treat OIDs with more respect (avoid using ints, use macros for
5252
* conversion & comparison).
5353
*
54+
* Modifications - 10-May-2001 - pjw@rhyme.com.au
55+
* - Treat SEQUENCE SET TOC entries as data entries rather than schema
56+
* entries.
57+
* - Make allowance for data entries that did not have a data dumper
58+
* routine (eg. SEQUENCE SET)
59+
*
5460
*-------------------------------------------------------------------------
5561
*/
5662

@@ -154,6 +160,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
154160
int reqs;
155161
OutputContext sav;
156162
int impliedDataOnly;
163+
bool defnDumped;
157164

158165
AH->ropt = ropt;
159166

@@ -276,78 +283,99 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
276283
}
277284
}
278285

286+
defnDumped = false;
287+
279288
if ((reqs & 1) != 0) /* We want the schema */
280289
{
281290
/* Reconnect if necessary */
282291
_reconnectAsOwner(AH, "-", te);
283292

284293
ahlog(AH, 1, "Creating %s %s\n", te->desc, te->name);
285294
_printTocEntry(AH, te, ropt, false);
295+
defnDumped = true;
286296

287297
/* If we created a DB, connect to it... */
288298
if (strcmp(te->desc, "DATABASE") == 0)
289299
{
290300
ahlog(AH, 1, "Connecting to new DB '%s' as %s\n", te->name, te->owner);
291301
_reconnectAsUser(AH, te->name, te->owner);
292302
}
293-
}
303+
}
294304

295305
/*
296-
* If we want data, and it has data, then restore that too
306+
* If we have a data component, then process it
297307
*/
298-
if (AH->PrintTocDataPtr !=NULL && (reqs & 2) != 0)
308+
if ( (reqs & 2) != 0 )
299309
{
300-
#ifndef HAVE_LIBZ
301-
if (AH->compression != 0)
302-
die_horribly(AH, "%s: Unable to restore data from a compressed archive\n", progname);
303-
#endif
304-
305-
_printTocEntry(AH, te, ropt, true);
306-
307-
/*
308-
* Maybe we can't do BLOBS, so check if this node is for BLOBS
310+
/* hadDumper will be set if there is genuine data component for this
311+
* node. Otherwise, we need to check the defn field for statements
312+
* that need to be executed in data-only restores.
309313
*/
310-
if ((strcmp(te->desc, "BLOBS") == 0) && !_canRestoreBlobs(AH))
314+
if (te->hadDumper)
311315
{
312-
ahprintf(AH, "--\n-- SKIPPED \n--\n\n");
313-
314316
/*
315-
* This is a bit nasty - we assume, for the moment, that
316-
* if a custom output is used, then we don't want
317-
* warnings.
317+
* If we can output the data, then restore it.
318318
*/
319-
if (!AH->CustomOutPtr)
320-
fprintf(stderr, "%s: WARNING - skipping BLOB restoration\n", progname);
321-
322-
}
323-
else
324-
{
325-
326-
_disableTriggersIfNecessary(AH, te, ropt);
327-
328-
/*
329-
* Reconnect if necessary (_disableTriggers may have
330-
* reconnected)
331-
*/
332-
_reconnectAsOwner(AH, "-", te);
333-
334-
ahlog(AH, 1, "Restoring data for %s \n", te->name);
335-
336-
/*
337-
* If we have a copy statement, use it. As of V1.3, these
338-
* are separate to allow easy import from withing a
339-
* database connection. Pre 1.3 archives can not use DB
340-
* connections and are sent to output only.
341-
*
342-
* For V1.3+, the table data MUST have a copy statement so
343-
* that we can go into appropriate mode with libpq.
344-
*/
345-
if (te->copyStmt && strlen(te->copyStmt) > 0)
346-
ahprintf(AH, te->copyStmt);
347-
348-
(*AH->PrintTocDataPtr) (AH, te, ropt);
319+
if (AH->PrintTocDataPtr !=NULL && (reqs & 2) != 0)
320+
{
321+
#ifndef HAVE_LIBZ
322+
if (AH->compression != 0)
323+
die_horribly(AH, "%s: Unable to restore data from a compressed archive\n",
324+
progname);
325+
#endif
349326

350-
_enableTriggersIfNecessary(AH, te, ropt);
327+
_printTocEntry(AH, te, ropt, true);
328+
329+
/*
330+
* Maybe we can't do BLOBS, so check if this node is for BLOBS
331+
*/
332+
if ((strcmp(te->desc, "BLOBS") == 0) && !_canRestoreBlobs(AH))
333+
{
334+
ahprintf(AH, "--\n-- SKIPPED \n--\n\n");
335+
336+
/*
337+
* This is a bit nasty - we assume, for the moment, that
338+
* if a custom output is used, then we don't want
339+
* warnings.
340+
*/
341+
if (!AH->CustomOutPtr)
342+
fprintf(stderr, "%s: WARNING - skipping BLOB restoration\n", progname);
343+
344+
}
345+
else
346+
{
347+
348+
_disableTriggersIfNecessary(AH, te, ropt);
349+
350+
/*
351+
* Reconnect if necessary (_disableTriggers may have
352+
* reconnected)
353+
*/
354+
_reconnectAsOwner(AH, "-", te);
355+
356+
ahlog(AH, 1, "Restoring data for %s \n", te->name);
357+
358+
/*
359+
* If we have a copy statement, use it. As of V1.3, these
360+
* are separate to allow easy import from withing a
361+
* database connection. Pre 1.3 archives can not use DB
362+
* connections and are sent to output only.
363+
*
364+
* For V1.3+, the table data MUST have a copy statement so
365+
* that we can go into appropriate mode with libpq.
366+
*/
367+
if (te->copyStmt && strlen(te->copyStmt) > 0)
368+
ahprintf(AH, te->copyStmt);
369+
370+
(*AH->PrintTocDataPtr) (AH, te, ropt);
371+
372+
_enableTriggersIfNecessary(AH, te, ropt);
373+
}
374+
}
375+
} else if (!defnDumped) {
376+
/* If we haven't already dumped the defn part, do so now */
377+
ahlog(AH, 1, "Executing %s %s\n", te->desc, te->name);
378+
_printTocEntry(AH, te, ropt, false);
351379
}
352380
}
353381
te = te->next;
@@ -1829,26 +1857,22 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt)
18291857
return 0;
18301858
}
18311859

1832-
/* Special Case: If 'SEQUENCE SET' and schemaOnly, then not needed */
1833-
if (ropt->schemaOnly && (strcmp(te->desc, "SEQUENCE SET") == 0))
1834-
return 0;
1860+
/* Special Case: If 'SEQUENCE SET' then it is considered a data entry */
1861+
if (strcmp(te->desc, "SEQUENCE SET") == 0)
1862+
res = res & 2;
18351863

18361864
/* Mask it if we only want schema */
18371865
if (ropt->schemaOnly)
18381866
res = res & 1;
18391867

18401868
/* Mask it we only want data */
1841-
if (ropt->dataOnly && (strcmp(te->desc, "SEQUENCE SET") != 0))
1869+
if (ropt->dataOnly)
18421870
res = res & 2;
18431871

18441872
/* Mask it if we don't have a schema contribition */
18451873
if (!te->defn || strlen(te->defn) == 0)
18461874
res = res & 2;
18471875

1848-
/* Mask it if we don't have a possible data contribition */
1849-
if (!te->hadDumper)
1850-
res = res & 1;
1851-
18521876
/* Finally, if we used a list, limit based on that as well */
18531877
if (ropt->limitToList && !ropt->idWanted[te->id - 1])
18541878
return 0;

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*
1919
* IDENTIFICATION
20-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.32 2001/04/25 07:03:19 pjw Exp $
20+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.33 2001/05/12 01:03:59 pjw Exp $
2121
*
2222
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2323
* - Initial version.
@@ -68,7 +68,7 @@ typedef z_stream *z_streamp;
6868

6969
#define K_VERS_MAJOR 1
7070
#define K_VERS_MINOR 5
71-
#define K_VERS_REV 5
71+
#define K_VERS_REV 6
7272

7373
/* Data block types */
7474
#define BLK_DATA 1

src/bin/pg_dump/pg_dump.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.205 2001/04/25 07:03:19 pjw Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.206 2001/05/12 01:03:59 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -127,6 +127,12 @@
127127
* - Don't dump CHECK constraints with same source and names both
128128
* starting with '$'.
129129
*
130+
* Modifications - 10-May-2001 - pjw@rhyme.com.au
131+
*
132+
* - Don't dump COMMENTs in data-only dumps
133+
* - Fix view dumping SQL for V7.0
134+
* - Fix bug when getting view oid with long view names
135+
*
130136
*-------------------------------------------------------------------------
131137
*/
132138

@@ -2047,15 +2053,37 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
20472053
* (sequence) or 'v' (view).
20482054
*/
20492055

2050-
appendPQExpBuffer(query,
2056+
if (g_fout->remoteVersion >= 70100)
2057+
{
2058+
appendPQExpBuffer(query,
20512059
"SELECT pg_class.oid, relname, relkind, relacl, "
2052-
"(select usename from pg_user where relowner = usesysid) as usename, "
2060+
"(select usename from pg_user where relowner = usesysid) as usename, "
20532061
"relchecks, reltriggers, relhasindex "
20542062
"from pg_class "
20552063
"where relname !~ '^pg_' "
20562064
"and relkind in ('%c', '%c', '%c') "
20572065
"order by oid",
20582066
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
2067+
} else {
2068+
/*
2069+
* In 7.1, view relkind was not set to 'v', so we fake this by checking
2070+
* if we have a view by looking up pg_class & pg_rewrite.
2071+
*/
2072+
appendPQExpBuffer(query,
2073+
"SELECT c.oid, relname, relacl, "
2074+
"CASE WHEN relhasrules and relkind = 'r' "
2075+
" And EXISTS(SELECT r.rulename FROM pg_rewrite r WHERE "
2076+
" r.ev_class = c.oid AND r.ev_type = '1'::\"char\") "
2077+
"THEN 'v'::\"char\" "
2078+
"ELSE relkind End AS relkind,"
2079+
"relacl, (select usename from pg_user where relowner = usesysid) as usename, "
2080+
"relchecks, reltriggers, relhasindex "
2081+
"from pg_class c "
2082+
"where relname !~ '^pg_' "
2083+
"and relkind in ('%c', '%c', '%c') "
2084+
"order by oid",
2085+
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
2086+
}
20592087

20602088
res = PQexec(g_conn, query->data);
20612089
if (!res ||
@@ -2103,9 +2131,9 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21032131
resetPQExpBuffer(query);
21042132
appendPQExpBuffer(query, "SELECT definition as viewdef, ");
21052133
/* XXX 7.2 - replace with att from pg_views or some other generic source */
2106-
appendPQExpBuffer(query, "(select oid from pg_rewrite where rulename='_RET'"
2107-
" || viewname) as view_oid from pg_views"
2108-
" where viewname = ");
2134+
appendPQExpBuffer(query, "(select oid from pg_rewrite where "
2135+
" rulename=('_RET' || viewname)::name) as view_oid"
2136+
" from pg_views where viewname = ");
21092137
formatStringLiteral(query, tblinfo[i].relname, CONV_ALL);
21102138
appendPQExpBuffer(query, ";");
21112139

@@ -2974,6 +3002,10 @@ dumpComment(Archive *fout, const char *target, const char *oid)
29743002
PQExpBuffer query;
29753003
int i_description;
29763004

3005+
/* Comments are SCHEMA not data */
3006+
if (dataOnly)
3007+
return;
3008+
29773009
/*** Build query to find comment ***/
29783010

29793011
query = createPQExpBuffer();

0 commit comments

Comments
 (0)